Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Jul 10, 2025

Fixes add/sub overflow bug

x # => 0.1e9223372036854775793
x+x       #=> 0.0  (Expected: huge positive value or infinity)
x-(-x)    #=> 0.0  (Expected: huge positive value or infinity)
(-x)+(-x) #=> -0.0 (Expected: huge negative value or -infinity)
(-x)-x    #=> -0.0 (Expected: huge negative value or -infinity)

Fixes div and mult overflow/underflow bug: wrong sign

large_x #=> 0.1e4611686018427387905
small_x #=> 0.1e-9223372036854775807

large_x * (-large_x) #=> Infinity (Expected: -Infinity)
small_x * (-small_x) #=> 0.0 (Expected: -0.0)
large_x.div(-small_x, 10) #=> Infinity (Expected: -Infinity)
small_x.div(-large_x, 10) #=> 0.0 (Expected: -0.0)

No test for add/sub because it is hard to make a reproducible bigdecimal with large exponent, some unrelated bug is a blocker of writing test.

tompng added 2 commits July 11, 2025 00:10
Check VpIsInf before VpSetSign.
`VpSetSign(c, sign)` will clear the infinity result.
@tompng tompng changed the title Fix a bug that exponent overflow is ignored in x+y and x-y Fix a bug that exponent overflow is ignored in add, sub, mult and div operation Jul 10, 2025
@tompng tompng merged commit a35090b into ruby:master Jul 10, 2025
78 checks passed
@tompng tompng deleted the addsub_overflow_ignore_bugfix branch July 10, 2025 18:04
@tompng tompng added the bug label Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant