diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-14 06:10:01 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-14 06:10:01 +0000 |
commit | 4c2e2d8bdefa8cd43adf1e28358353c1ded53049 (patch) | |
tree | 223830f7eec30a6ea0b2ba335c17547f3f7c51b7 /numeric.c | |
parent | 092db4dcf0a6c9b0dc0408d4f29189754a07212e (diff) | |
download | ruby-4c2e2d8bdefa8cd43adf1e28358353c1ded53049.tar.gz |
* 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/trunk@35013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -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 @@ -2733,12 +2745,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, '%'); } |