Dividing BitLen by math.Log2(10) is what math/big does underneath
Not including the Int64/Uint64 check makes this slightly slower than old method
Included 2 benchmarks, for 10 digit numbers & 100 digit numbers:
-- before
> go test -bench=NumDigit -run=NumDigit
goos: linux
goarch: amd64
pkg: github.com/shopspring/decimal
cpu: AMD Ryzen 7 7840U w/ Radeon 780M Graphics
BenchmarkDecimal_NumDigits10-16 18317293 63.87 ns/op
BenchmarkDecimal_NumDigits100-16 3645015 329.6 ns/op
-- after
...
BenchmarkDecimal_NumDigits10-16 143781325 8.488 ns/op
BenchmarkDecimal_NumDigits100-16 5931247 207.4 ns/op
Given the interface definition
type Ordered[T any] interface {
Compare(T) int
}
And the type constraint T Ordered[T], make decimal.Decimal satisfy this
constraint, so that generic code written against T Ordered[T] can work
with decimal values as smoothly as it works with time.Time values today.
Fixes: #345
* Change function name from RoundUp -> RoundCeil, RoundDown -> RoundFloor
* Add a new RoundUp and RoundDown methods
* Modify the docs of RoundUp and RoundDown
Since trailing 0 digits after the decimal point are trimmed, intString
becomes an empty string when there is no digit before the decimal point
and all digits after the decimal point is 0, causing big.Int SetString
to fail because there is no string to parse.
Fix#134.
* Make NewFromFloat respect the precision of the input
Restores the previous behaviour where input converted from float is truncated at the precision of the float.
The precision is depending on the actual value. Simply making it 15 digits would make it faster, but would in some cases lose some precision. So the code from the stdlib that does this calculation (very well) has been included.
Lots of good articles here: https://www.exploringbinary.com/decimal-precision-of-binary-floating-point-numbers/
Performance is around the same as the previous string roundtrip since it basically does the same, but allocations are a bit less.
`BenchmarkNewFromStringFloat` is the old method, `BenchmarkNewFromFloat` is the new.
```
BenchmarkNewFromFloatWithExponent-8 10000000 260 ns/op 174 B/op 4 allocs/op
BenchmarkNewFromFloat-8 2000000 744 ns/op 90 B/op 2 allocs/op
BenchmarkNewFromStringFloat-8 2000000 822 ns/op 258 B/op 6 allocs/op
```
* Update Sin/Tan/Cos tests.
* Added Atan method
* added sin and cos methods
* added tests for atan, sin, and cos
* tan method and test
* potentinal fix for './decimal_test.go:261:6: d declared but not used' error thrown by the tip version Travis CI tests + corrected comment in decimal.go