bbgo_origin/pkg/fixedpoint/dec_dnum_test.go

38 lines
1.1 KiB
Go
Raw Normal View History

2022-02-15 02:56:09 +00:00
//go:build dnum
package fixedpoint
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestDelta(t *testing.T) {
f1 := MustNewFromString("0.0009763593380614657")
f2 := NewFromInt(42300)
assert.InDelta(t, f1.Mul(f2).Float64(), 41.3, 1e-14)
}
func TestInternal(t *testing.T) {
r := &reader{"1.1e-15", 0}
c, e := r.getCoef()
assert.Equal(t, uint64(1100000000000000), c)
assert.Equal(t, 1, e)
f := MustNewFromString("1.1e-15")
digits := getDigits(f.coef)
assert.Equal(t, "11", digits)
f = MustNewFromString("1.00000000000000111")
assert.Equal(t, "1.000000000000001", f.String())
f = MustNewFromString("1.1e-15")
assert.Equal(t, "0.0000000000000011", f.String())
assert.Equal(t, 16, f.NumFractionalDigits())
f = MustNewFromString("1.00000000000000111")
assert.Equal(t, "1.000000000000001", f.String())
f = MustNewFromString("0.00000000000000000001000111")
assert.Equal(t, "0.00000000000000000001000111", f.String())
f = MustNewFromString("0.000000000000000000001000111")
assert.Equal(t, "1.000111e-21", f.String())
f = MustNewFromString("1e-100")
assert.Equal(t, 100, f.NumFractionalDigits())
}