Skip to content

Tags: flemeur/decimal

Tags

v1.2.0

Toggle v1.2.0's commit message
Version 1.2.0

v1.1.0

Toggle v1.1.0's commit message
initialize go modules

1.1.0

Toggle 1.1.0's commit message
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.

1.0.1

Toggle 1.0.1's commit message
RequireFromString (shopspring#73)

fmt

1.0.0

Toggle 1.0.0's commit message
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.