Backport #2364
closedFloat conversion of NaN in 1.8.x
Description
=begin
Trying to fix issue #2349 for 1.8.8 but running into a small problem: conversion to a float will fail if the value converted corresponds to NaN:
$ ruby19 -r bigdecimal -e "p Float(BigDecimal('NaN'))"
NaN
$ ruby18 -r bigdecimal -e "p Float(BigDecimal('NaN'))"
ArgumentError: invalid value for Float()
This is true of any class for which #to_f returns NaN.
This makes it impossible for BigDecimal("NaN") to be converted to a float in 1.8.
Can anyone think of a reason not to bring 1.8 inline with 1.9 (by allowing NaN)?
diff --git a/object.c b/object.c
index 4704ebf..dd67039 100644
--- a/object.c
+++ b/object.c
@@ -2486,13 +2486,7 @@ rb_Float(val)
break;
default:
-
{
-
VALUE f = rb_convert_type(val, T_FLOAT, "Float", "to_f");
-
if (isnan(RFLOAT(f)->value)) {
-
rb_raise(rb_eArgError, "invalid value for Float()");
-
}
-
return f;
-
}
-
}return rb_convert_type(val, T_FLOAT, "Float", "to_f");
}
(Doesn't generate any error in make test or test-all)
=end
Updated by ujihisa (Tatsuhiro Ujihisa) over 14 years ago
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
=begin
=end
Updated by marcandre (Marc-Andre Lafortune) over 14 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
=begin
This issue was solved with changeset r26032.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end
Updated by shyouhei (Shyouhei Urabe) about 14 years ago
- Status changed from Closed to Assigned
- Assignee changed from nobu (Nobuyoshi Nakada) to shyouhei (Shyouhei Urabe)
=begin
=end
Updated by shyouhei (Shyouhei Urabe) about 14 years ago
- Assignee changed from shyouhei (Shyouhei Urabe) to wyhaines (Kirk Haines)
=begin
1.8.6 has this issue.
=end
Updated by wyhaines (Kirk Haines) almost 14 years ago
- Status changed from Assigned to Closed
=begin
This issue was solved with changeset r28392.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end