summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-30 05:13:10 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-30 05:13:10 +0000
commit9c0d94449bd9f6304179ecdb9294b30cb6e51319 (patch)
tree3aa680e2ebf27da2fd68d20a7c00cd43c71393b8 /numeric.c
parent0b81093a7e7a4c4283b1918672f7fed83e545a1c (diff)
merge revision(s) 35013:
* numeric.c: fix flodivmod for cornercases [Bug #6044] add ruby_float_mod * insns.def (opt_mod): use ruby_float_mod * internal.h: declare ruby_float_mod * test/ruby/test_float.rb: tests for above * test/ruby/envutil.rb: create helper assert_is_minus_zero git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/numeric.c b/numeric.c
index c05aaee8fd..497b93b85d 100644
--- a/numeric.c
+++ b/numeric.c
@@ -817,7 +817,9 @@ flodivmod(double x, double y, double *divp, double *modp)
#ifdef HAVE_FMOD
mod = fmod(x, y);
#else
- {
+ if((x == 0.0) || (isinf(y) && !isinf(x)))
+ mod = x;
+ else {
double z;
modf(x/y, &z);
@@ -836,6 +838,17 @@ flodivmod(double x, double y, double *divp, double *modp)
if (divp) *divp = div;
}
+/*
+ * Returns the modulo of division of x by y.
+ * An error will be raised if y == 0.
+ */
+
+double ruby_float_mod(double x, double y) {
+ double mod;
+ flodivmod(x, y, 0, &mod);
+ return mod;
+}
+
/*
* call-seq:
@@ -851,7 +864,7 @@ flodivmod(double x, double y, double *divp, double *modp)
static VALUE
flo_mod(VALUE x, VALUE y)
{
- double fy, mod;
+ double fy;
switch (TYPE(y)) {
case T_FIXNUM:
@@ -866,8 +879,7 @@ flo_mod(VALUE x, VALUE y)
default:
return rb_num_coerce_bin(x, y, '%');
}
- flodivmod(RFLOAT_VALUE(x), fy, 0, &mod);
- return DBL2NUM(mod);
+ return DBL2NUM(ruby_float_mod(RFLOAT_VALUE(x), fy));
}
static VALUE
@@ -2648,12 +2660,7 @@ fix_mod(VALUE x, VALUE y)
x = rb_int2big(FIX2LONG(x));
return rb_big_modulo(x, y);
case T_FLOAT:
- {
- double mod;
-
- flodivmod((double)FIX2LONG(x), RFLOAT_VALUE(y), 0, &mod);
- return DBL2NUM(mod);
- }
+ return DBL2NUM(ruby_float_mod((double)FIX2LONG(x), RFLOAT_VALUE(y)));
default:
return rb_num_coerce_bin(x, y, '%');
}