-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add/subtract loose the scale when value is zero #284
Comments
Hi @glureau, thanks for reporting and for offering help, it's appreciated! I'll give the issue a look over the weekend and get back to you. |
Sorry didn't have time this weekend to look into it, hopefully next one :( |
Hi @glureau, If you take a look at what happens when scale is applied, in last line of this block we are creating a new Lines 1053 to 1066 in 1f61d2a
And then if we follow what happens next we can see that we end up in line 88 that sets the precision to 0, and that I think is not correct. Lines 76 to 97 in 1f61d2a
I think the fix should go there, and hardcode the precision in line 88 (when wrk is determined to be equal to zero) to a value of 1, because I think precision of zero is irrelevant as long as it's not 0. Also I think that multiplication to calculate the exponent is pointless since the significand is zero, but I can't recall the reason why I wrote it like that, maybe it was a copy-paste from some case where it had meaning. Would you like to look into this and submit a PR? |
Describe the bug
Operations like addition or subtraction are loosing the scale when one of the operand value is zero with a scale of zero.
To Reproduce
Expected behavior
A clear and concise description of what you expected to happen.
Platform
== ZERO
I presume it's impacting every platforms.Additional context
I read a bit the code, I presume it's related to this initial condition, as decimalMode.isPrecisionUnlimited is true (because I don't really need to define the precision here) then I don't calculate the best scale.
kotlin-multiplatform-bignum/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt
Lines 1561 to 1580 in 1f61d2a
I'm open to push a PR if there's a clear way to go. I guess I could change this DEFAULT with a
.copy(scale = ...)
but no idea if it's the right approach.PS : Thanks for your work, greatly appreciated!
The text was updated successfully, but these errors were encountered: