diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-03-10 13:15:50 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2021-03-12 07:35:18 -0800 |
commit | aaab3b1de943c3317e115d623ffc7908b4c96578 (patch) | |
tree | 8665765ba9bd35801f514322178c63974c90ae32 /numeric.c | |
parent | 701001e36ea99f0c253eeb0721706af77de0ffdd (diff) | |
download | ruby-aaab3b1de943c3317e115d623ffc7908b4c96578.tar.gz |
Fix integer/float remainder with infinity argument of opposite sign
Previously, the result was incorrect:
4.remainder(-Float::INFINITY)
Before: => NaN
After: => 4
4.2.remainder(-Float::INFINITY)
Before: => NaN
After: => 4.2
Fixes [Bug #6120]
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -656,6 +656,11 @@ num_remainder(VALUE x, VALUE y) rb_num_positive_int_p(y)) || (rb_num_positive_int_p(x) && rb_num_negative_int_p(y)))) { + if (RB_TYPE_P(y, T_FLOAT)) { + if (isinf(RFLOAT_VALUE(y))) { + return x; + } + } return rb_funcall(z, '-', 1, y); } return z; @@ -1151,11 +1156,11 @@ flodivmod(double x, double y, double *divp, double *modp) div = x; else { div = (x - mod) / y; - if (modp && divp) div = round(div); + if (modp && divp) div = round(div); } if (y*mod < 0) { - mod += y; - div -= 1.0; + mod += y; + div -= 1.0; } if (modp) *modp = mod; if (divp) *divp = div; |