Giter Site home page Giter Site logo

Bad Cmp result about decimal HOT 17 CLOSED

ericlagergren avatar ericlagergren commented on May 20, 2024
Bad Cmp result

from decimal.

Comments (17)

ericlagergren avatar ericlagergren commented on May 20, 2024 1

ahhh I see the problem, thanks.

from decimal.

rif avatar rif commented on May 20, 2024

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.

ericlagergren avatar ericlagergren commented on May 20, 2024

can you reproduce this on the dev branch?

from decimal.

ericlagergren avatar ericlagergren commented on May 20, 2024

I ask because I think the fix is on the dev branch atm.

from decimal.

rif avatar rif commented on May 20, 2024

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.

ericlagergren avatar ericlagergren commented on May 20, 2024

could you post minimal repros for the bugs?

from decimal.

rif avatar rif commented on May 20, 2024

unfortunately not, I will try to push a test on your dev branch.

from decimal.

ericlagergren avatar ericlagergren commented on May 20, 2024

okay. I can't begin debugging this until I have a couple test cases to look at.

from decimal.

rif avatar rif commented on May 20, 2024

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.

rif avatar rif commented on May 20, 2024

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.

rif avatar rif commented on May 20, 2024

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.

rif avatar rif commented on May 20, 2024
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.

ericlagergren avatar ericlagergren commented on May 20, 2024

I actually think a bad test case is why this is goofed.

from decimal.

ericlagergren avatar ericlagergren commented on May 20, 2024

yeah, this 63aaff2#diff-e035ddc6d9eb583a74a989c446aad535R168 was causing my tests to be wrong so the resulting code was wrong.

from decimal.

ericlagergren avatar ericlagergren commented on May 20, 2024

@rif if this is still an issue feel free to reopen.

from decimal.

rif avatar rif commented on May 20, 2024

All good on my side now. Thanks again!

from decimal.

ericlagergren avatar ericlagergren commented on May 20, 2024

from decimal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.