Commit graph

3 commits

Author SHA1 Message Date
jonson
867ed12000
fix the rounding bug in roundShortest method (#161)
* fix: fix rounding in FormatFloat fallback path
2020-07-07 09:05:46 +02:00
Mateusz Woś
480f653de8
Update documentation, clean up package level documentation (#173)
* Update documentation, clean up package level documentation
2020-04-27 22:35:36 -04:00
Klaus Post
cd690d0c9e Make NewFromFloat respect the precision of the input (#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.
2018-07-09 16:31:17 -04:00