summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-03 16:34:24 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-03 16:34:24 +0000
commit6c1c35db17e55adc479db493cd85e1ad8afa8e31 (patch)
tree944871f9360019658a0d1eb714d8301028c850a6 /ext/bigdecimal
parentb3085ba508b9582ff279c2ddf59a44885e22c074 (diff)
* ext/bigdecimal/bigdecimal.c (BigDecimal_DoDivmod): fix infinity
handling. 1 / Infinity was evaluated to NaN. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 3dd62f11fb6..5450f7594ab 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -944,10 +944,25 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
SAVE(b);
if(VpIsNaN(a) || VpIsNaN(b)) goto NaN;
- if(VpIsInf(a) || VpIsInf(b)) goto NaN;
+ if(VpIsInf(a) && VpIsInf(b)) goto NaN;
if(VpIsZero(b)) {
rb_raise(rb_eZeroDivError, "divided by 0");
}
+ if(VpIsInf(a)) {
+ GUARD_OBJ(d,VpCreateRbObject(1, "0"));
+ VpSetInf(d,(S_INT)(VpGetSign(a) == VpGetSign(b) ? 1 : -1));
+ GUARD_OBJ(c,VpCreateRbObject(1, "NaN"));
+ *div = d;
+ *mod = c;
+ return Qtrue;
+ }
+ if(VpIsInf(b)) {
+ GUARD_OBJ(d,VpCreateRbObject(1, "0"));
+ VpSetSign(d,(S_INT)(VpGetSign(a) == VpGetSign(b) ? 1 : -1));
+ *div = d;
+ *mod = a;
+ return Qtrue;
+ }
if(VpIsZero(a)) {
GUARD_OBJ(c,VpCreateRbObject(1, "0"));
GUARD_OBJ(d,VpCreateRbObject(1, "0"));