Tags: flemeur/decimal
Tags
Make NewFromFloat respect the precision of the input (shopspring#100) * 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.
Fix Floor() and Ceil() for integer values (shopspring#64) Implementation of aforementioned methods applied an integer multiplier to int part, and rejected the exponent. This did not work well for positive exponent values - multiplier was supposed to be a non-integer value less than 1, but was rounded up to it. This caused different results for equal Decimal values like decimal.New(19, 1) and decimal.New(1900, -1). Now functions return the receiver if it represents an integer value. This also reduces execution time for previously broken cases.