1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* numeric.c (flo_cmp): should always return nil for NaN.

* numeric.c (flo_cmp): handle infinite value specially using
  infinite? method internally.  [ruby-dev:38681]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-06-19 08:19:14 +00:00
parent 5134783cde
commit cdba56b38a
2 changed files with 13 additions and 0 deletions

View file

@ -1,3 +1,10 @@
Fri Jun 19 17:04:59 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (flo_cmp): should always return nil for NaN.
* numeric.c (flo_cmp): handle infinite value specially using
infinite? method internally. [ruby-dev:38681]
Fri Jun 19 09:28:45 2009 Tadayoshi Funaba <tadf@dotrb.org>
* numeric.c (*_numerator,*_denominator): moved to rational.c.

View file

@ -937,6 +937,7 @@ flo_cmp(VALUE x, VALUE y)
double a, b;
a = RFLOAT_VALUE(x);
if (isnan(a)) return Qnil;
switch (TYPE(y)) {
case T_FIXNUM:
b = (double)FIX2LONG(y);
@ -955,6 +956,11 @@ flo_cmp(VALUE x, VALUE y)
break;
default:
if (isinf(a) && (!rb_respond_to(y, rb_intern("infinite?")) ||
!RTEST(rb_funcall(y, rb_intern("infinite?"), 0, 0)))) {
if (a > 0.0) return INT2FIX(1);
return INT2FIX(-1);
}
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
}
return rb_dbl_cmp(a, b);