Skip to content
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

Wrong result when adding two decimals #62

Closed
jonathan-laurent opened this issue Sep 11, 2024 · 0 comments · Fixed by #63
Closed

Wrong result when adding two decimals #62

jonathan-laurent opened this issue Sep 11, 2024 · 0 comments · Fixed by #63

Comments

@jonathan-laurent
Copy link

I observed this behaviour using Decimals v0.4.1 and Julia 1.10.5 (latest):

using Decimals
x = parse(Decimal, "1.0000000000000000758")
print(string(x + 1))  # shows: "0.1553255926290449142" (?!)
barucden added a commit to barucden/Decimals.jl that referenced this issue Oct 2, 2024
The addition did not work for two numbers with exponents `q1` and `q2`
such that `d = abs(q1 - q2) > 18` because it led to a power `10^d` which
overflows for `d>18`. This commit makes that `10` a `BigInt` to prevent
overflow.

Fixes JuliaMath#62
barucden added a commit to barucden/Decimals.jl that referenced this issue Oct 2, 2024
The addition did not work for two numbers with exponents `q1` and `q2`
such that `d = abs(q1 - q2) > 18` because it led to a power `10^d` which
overflows for `d>18`. This commit makes that `10` a `BigInt` to prevent
overflow.

Besides that, the code is simplified a little.

Fixes JuliaMath#62
@barucden barucden mentioned this issue Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant