Comments (17)
ahhh I see the problem, thanks.
from decimal.
I printed the internals if it helps:
RESULT: 9223372036854775807, scale: 5, ctx: {precision:0 mode:0}, form: 1, unscaled: {false [270100000]}
EXPECTED: compact: 2701, scale: 0, ctx: {precision:0 mode:0}, form: 1, unscaled: {false []}
Some other values with similar problem:
RESULT: compact: 9223372036854775807, scale: 5, ctx: {precision:0 mode:0}, form: 1, unscaled: {false [181050000]}
EXPECTED: compact: 18105, scale: 1, ctx: {precision:0 mode:0}, form: 1, unscaled: {false []}
from decimal.
can you reproduce this on the dev branch?
from decimal.
I ask because I think the fix is on the dev branch atm.
from decimal.
I confirm that the dev branch fixes the first problem (the one with 2701) but the second one with 1810.5 is NOT fixed. Also I got two other tests that fail: before the result was 0.3 after a Round(9) and now it's 0.300000001
from decimal.
could you post minimal repros for the bugs?
from decimal.
unfortunately not, I will try to push a test on your dev branch.
from decimal.
okay. I can't begin debugging this until I have a couple test cases to look at.
from decimal.
Would this type of test help?
func TestBig_CmpUnscale(t *testing.T) {
b1 := &Big{compact: 9223372036854775807, scale: 5, ctx: Context{precision: 0, mode: RoundingMode(0)}, form: 1, unscaled: *new(big.Int).SetInt64(181050000)}
b2 := &Big{compact: 18105, scale: 1, ctx: Context{precision: 0, mode: RoundingMode(0)}, form: 1, unscaled: *new(big.Int).SetInt64(0)}
if b1.Cmp(b2) != 0 {
t.Errorf("failed comparing %v with %v: %v", b1, b2, b1.Cmp(b2))
}
}
from decimal.
So I added this test on the dev branch and on my machine there are three tests failing:
--- FAIL: TestBig_Cmp (0.00s)
decimal_test.go:170: #10: wanted 0, got -1
--- FAIL: TestBig_IsBig (0.00s)
decimal_test.go:191: #4: wanted true, got false
--- FAIL: TestBig_CmpUnscale (0.00s)
decimal_test.go:569: failed comparing 1810.5 with 1810.5: 1
from decimal.
I confirm that the above issues are fixed but now I encountered:
t.Log(x.String(), y.String(), x.Cmp(y))
0.1 0.016666666666666666 -1
from decimal.
x = compact: 1000000000000000, scale: 16, ctx: {16 0}, form: form(1), unscaled: {false []}
y = compact: 16666666666666666, scale: 18, ctx: {0 0}, form: form(1), unscaled: {false []}
x.String() = 0.1
y.String() = 0.016666666666666666
x.Cmp(y) = -1
from decimal.
I actually think a bad test case is why this is goofed.
from decimal.
yeah, this 63aaff2#diff-e035ddc6d9eb583a74a989c446aad535R168 was causing my tests to be wrong so the resulting code was wrong.
from decimal.
@rif if this is still an issue feel free to reopen.
from decimal.
All good on my side now. Thanks again!
from decimal.
from decimal.
Related Issues (20)
- Separate benchmarks to their own package? HOT 5
- trim trailing 0s HOT 7
- SetString("3,60") returns a NaN instead of an error HOT 6
- Decompose interface interfering and breaking HOT 8
- Split a value x ways
- Mantissa retrieval? HOT 3
- Big.Float64() returns incorrect results for large integers
- Precision on math.Ceil HOT 1
- [Critical] Invalid rounding algorithm implementation
- math: Pow returns wrong results when base is negative and power is an integer HOT 1
- UnmarshalBSON and MarshalBSON serialization HOT 2
- SetString("4e絙谶涩)鶤Ŭ廓+踁YÏ豒=iC÷綳") returns 4 instead of an error HOT 6
- undefined: math.MaxInt with Go 1.16 HOT 3
- Float64 conversion HOT 1
- ERROR cannot convert type: types.Decimal HOT 1
- When scale is negative, the result is sci HOT 2
- Incorrect string formatting when rounding up to include additional digit HOT 2
- Imports error
- Rounding issue (expect round up, but down) HOT 1
- Benchmarks add unnecessary dependencies HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decimal.