Commit graph

153 commits

Author SHA1 Message Date
Mateusz Woś
b11a7c46d7
Add implementation of CoefficientInt64 method (#244)
* Add implementation of CoefficientInt64 method
2021-09-10 15:48:44 +02:00
Denis
483a047db9
Improve performance of Abs() and Round() (#240) 2021-09-09 13:03:13 +02:00
James Harris
cc4584f0a5
Add slice range checks to UnmarshalBinary() (#232)
* Add slice range checks to `UnmarshalBinary()`.
* Avoid use of `%w` verb with `Errorf()` for compatibility with older Go versions.
2021-06-23 00:24:56 +02:00
Felipe Neuwald
501661573f
Add InexactFloat64 method (#205)
* Add func (d Decimal) MustFloat64()
* renames MustFloat64 to InexactFloat64
2021-03-30 01:12:37 +02:00
Vu Long (Drake)
f77bb07828
Modify Rounding methods (#220)
* Change function name from RoundUp -> RoundCeil, RoundDown -> RoundFloor
* Add a new RoundUp and RoundDown methods
* Modify the docs of RoundUp and RoundDown
2021-03-14 22:09:56 +01:00
Bharath Ramesh
9328d16578
Added XML support for NullDecimal (#192)
* Added UnmarshalText and MarshalText support for NullDecimal
* Add tests for XML operations on NullDecimal
2021-02-18 23:32:50 +01:00
Vu Long (Drake)
99f4d74cf2
Fix wrong return RoundUp/RoundDown because of value after rescaled is ignore (#202) 2021-01-18 00:50:46 +01:00
Jason Biegel
2740f7f782 update changelog 2021-01-09 23:26:47 -05:00
nknordeen
0cada0bdfe
optimize NewFromString a bit (#198)
* optimize NewFromString a bit

* add benchmark for large number

Co-authored-by: Nicholas Nordeen <nnordeen@fanatics.com>
2021-01-09 23:15:12 -05:00
Mateusz Woś
8bd41ac55d
Implement RoundUp and RoundDown methods (#196)
* Implement RoundUp and RoundDown methods
2020-12-11 13:41:11 -05:00
sreekanth370
66332b32a9
Add power architecture support (ppc64le) to CI configuration (#188) 2020-12-01 11:15:53 +01:00
Jason Biegel
13425bb201 added vs code to gitignore 2020-11-19 00:23:29 -05:00
Mateusz Woś
ebbf8bbe36
Implement new initialization function - NewFromFormattedString (#184)
* Implement new initialization function - NewFromFormattedString
* Redefine docstring
2020-09-14 19:29:03 +02:00
mwoss
5a22b86679 Fix documentation in RoundBank method 2020-08-20 23:47:45 +02:00
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ś
6fe01c1abd
Implement IsInteger method (#179) 2020-07-01 01:20:32 +02:00
Mateusz Woś
2568a29459
Release version 1.2.0 (#175)
v1.2
2020-04-28 17:23:09 -04: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
Mateusz Woś
c939845a68
Improve go report cards score (#174)
* Improve go report cards score
2020-04-27 02:03:21 -04:00
Mateusz Woś
1884f454f8
Add new helper methods: BigInt, BigFloat (#171)
* Add new helper methods: BigInt, BigFloat
* Add few tests cases showing loss of precision after casting
2020-04-20 00:29:39 +02:00
Mateusz Woś
f1c1aead5a
Drop support for Go versions older than 1.7 (#172)
* Drop support for Go versions older than 1.7
* Update README.md
2020-04-20 00:18:35 +02:00
Mateusz Woś
feafbe1d95
CI, test build on the three latest Go version and the oldest one available (#170) 2020-04-19 19:24:39 +02:00
Jason Biegel
02e2044944
Revert remove insignificant digits (#159)
* revert original remove insignificant change (PR 46), and add the logic back as a function
2020-02-27 15:28:07 -05:00
Jason Biegel
a08b92da27 add intellij to gitignore 2020-02-25 19:50:30 -05:00
Jason Biegel
6c07c6ca86
remove 15 interval RoundCash (#166)
* remove 15 interval RoundCash

* update function doc

* Remove comments and benchmark referring interval 15

Co-authored-by: Mateusz Woś <wos.mateusz16@gmail.com>
2020-02-25 19:44:03 -05:00
Mateusz Woś
408a2507e1
Remove unnecessary decimal rescaling - memory usage optimization (#160)
* Remove unnecessary decimal rescaling

* Move benchmarks to separate file, add new benchmark tests
2020-01-06 00:12:15 +01:00
Jason Biegel
96defcb63c Run go fmt (#162) 2020-01-05 15:46:53 +01:00
Mateusz Woś
360f2bc030
Add support for Go modules (#157) 2019-11-30 23:07:10 +01:00
Mathieu Post
bc70c3beb9 Add NewFromInt and NewFromInt32 (#72)
Add NewFromInt and NewFromInt32
2019-11-29 00:17:06 -05:00
Jason Biegel
ff9ed33395
reapply travis go version fix from 75bb2cb9 (#156) 2019-11-29 00:04:20 -05:00
Jason Biegel
b054a8dfd1 Revert "decimal: add decomposer interface"
This reverts commit 75bb2cb98e.
2019-11-24 22:55:19 -05:00
Jason Biegel
f1972eb1d1
Merge pull request #137 from lantw44/master
Fix decoding of .0
2019-10-08 22:57:16 -04:00
Jason Biegel
2677b5dba8
Merge pull request #144 from forsaken628/patch-1
fix: Coefficient panic
2019-10-08 22:49:08 -04:00
Jason Biegel
a36b5d85f3
Merge pull request #141 from kardianos/kardianos-decomposer
decimal: add decomposer interface
2019-09-05 10:42:23 -04:00
Daniel Theophanes
75bb2cb98e decimal: add decomposer interface
For golang/go#30870
2019-09-04 15:36:13 -07:00
coldWater
62587fc365
fix: Coefficient panic
call Coefficient on uninitialized Decimal will panic
2019-06-17 18:13:00 +08:00
Ting-Wei Lan
f39378d939 Fix decoding of .0
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.
2019-02-19 17:00:26 +08: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
Ian Norden
7e43aed1c9 Added cos, sin, tan, and atan methods and tests (#96)
* 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
2018-07-09 10:22:25 -04:00
José David Arévalo
19e3cb6c29 add functions IsPositive, IsNegative and IsZero (#88) 2018-06-07 10:48:47 -04:00
Steven Roose
2df3e6ddaf Add support for shifting in base 10 (#86)
This allows for very fast multiplying and dividing by powers of 10
without the possibility of losing precision.
2018-03-19 13:08:23 -04:00
Randy Pensinger
69b3a8ad1f RequireFromString (#73)
fmt
2018-03-01 16:32:36 -05:00
Igor Mikushkin
ca6009d707 Testing Float64 (#82)
* Additional (and some breaking) tests for NewFromFloatWithExponent

* Addressing tests for NewFromFloatWithExponent

* Naming cosmetic correction

* removing unused code

* Improving FromFloatWithExponent

* Tests for exact float representation added

* Exact float representation in FromFloat

* Adding breaking test for NewFromFloat

* Fast path in FromFloat is unreliable, fixing it

* Addressing special meaning of zero exponent in float64

* NewFromFloatWithExponent: subnormals support

* NewFromFloatWithExponent: just a few additional test cases

* NewFromFloat: documentation update

* NewFromFloatWithExponent: optimization and some documentation

* NewFromFloatWithExponent: optimizations

* NewFromFloatWithExponent: optimizations

* Subnormal test added

* Float64: adding tests
2018-03-01 16:31:53 -05:00
Igor Mikushkin
78e9b82f68 Exact representation in NewFromFloat (#78)
* Additional (and some breaking) tests for NewFromFloatWithExponent

* Addressing tests for NewFromFloatWithExponent

* Naming cosmetic correction

* removing unused code

* Improving FromFloatWithExponent

* Tests for exact float representation added

* Exact float representation in FromFloat

* Adding breaking test for NewFromFloat

* Fast path in FromFloat is unreliable, fixing it

* Addressing special meaning of zero exponent in float64

* NewFromFloatWithExponent: subnormals support

* NewFromFloatWithExponent: just a few additional test cases

* NewFromFloat: documentation update

* NewFromFloatWithExponent: optimization and some documentation

* NewFromFloatWithExponent: optimizations

* NewFromFloatWithExponent: optimizations
2018-03-01 16:29:43 -05:00
Igor Mikushkin
bf9a39e28b Addressing rounding and overflow issues in NewFromFloatWithExponent (#77)
* Additional (and some breaking) tests for NewFromFloatWithExponent

* Addressing tests for NewFromFloatWithExponent

* Naming cosmetic correction

* removing unused code

* Improving FromFloatWithExponent

* Addressing special meaning of zero exponent in float64

* NewFromFloatWithExponent: subnormals support

* NewFromFloatWithExponent: just a few additional test cases

* NewFromFloatWithExponent: optimization and some documentation

* NewFromFloatWithExponent: optimizations

* NewFromFloatWithExponent: optimizations
2018-03-01 16:29:13 -05:00
ivahaev
e3482495ff Added ensureInitialized() to the Neg() method (#80)
* Added ensureInitialized to the Neg() method,
because it can panic when d.value is nil

* TestDecimal_NegFromEmpty added
2018-01-26 16:25:43 -05:00
Chad Gilbert
a76a8bf60b Fix broken RoundBank func in #75 (#76) 2018-01-18 17:52:17 -05:00
Zheng Dayu
8dffa2b7c7 format usage code in README (#70) 2018-01-02 14:16:03 -05:00
tbrs
9ca7f51822 Fix Floor() and Ceil() for integer values (#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.
2017-11-08 17:52:54 -05:00
Cyrill Schumacher
faaed5fca7 Implement Swedish/Cash rounding fixes #63 (#66)
Performance and allocations not that good but can be optimized later.

RoundSwedish aka Cash/Penny/öre rounding rounds decimal to a specific
interval. The amount payable for a cash transaction is rounded to the nearest
multiple of the minimum currency unit available. The following intervals are
available: 5, 10, 15, 25, 50 and 100; any other number throws a panic.
    5:   5 cent rounding 3.43 => 3.45
   10:  10 cent rounding 3.45 => 3.50 (5 gets rounded up)
   15:  10 cent rounding 3.45 => 3.40 (5 gets rounded down)
   25:  25 cent rounding 3.41 => 3.50
   50:  50 cent rounding 3.75 => 4.00
  100: 100 cent rounding 3.50 => 4.00
For more details: https://en.wikipedia.org/wiki/Cash_rounding

BenchmarkDecimal_RoundSwedish/five-4         	 1000000	      1918 ns/op	    1164 B/op	      30 allocs/op
BenchmarkDecimal_RoundSwedish/fifteen-4      	  300000	      4331 ns/op	    2940 B/op	      74 allocs/op
2017-10-20 10:00:25 -04:00