Bug #11736 closed
Float(arg) not consistent with documentation
Added by bwheeler96 (Brian Wheeler) over 9 years ago.
Updated over 8 years ago.
Description
Float(arg) → float
Returns arg converted to a float. Numeric types are converted directly, the rest are converted using arg.to_f. Converting nil generates a TypeError.
Strings are NOT converted using arg.to_f
'123_INVALID'.to_f
# => 123.0
Float('123_INVALID')
# => ArgumentError
This could be fixed by changing object.c like so:
- return DBL2NUM(rb_str_to_dbl(val, TRUE));
+ return DBL2NUM(rb_str_to_dbl(val, FALSE));
But it appears that this is desired behavior as there are many specs to ensure this strict validity checking. Please update the documentation to reflect this.
Thanks,
Brian
Files
Description updated (diff )
Assignee set to zzak (zzak _)
Document is wrong.
Zack, could you fix it?
I have prepared a patch for this. Let me know what you think.
Status changed from Open to Closed
Applied in changeset r56421.
Assignee changed from zzak (zzak _) to hsbt (Hiroshi SHIBATA)
Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED
Backport changed from 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: UNKNOWN, 2.2: DONE, 2.3: REQUIRED
ruby_2_2 r56501 merged revision(s) 56421,56422.
Backport changed from 2.1: UNKNOWN, 2.2: DONE, 2.3: REQUIRED to 2.1: UNKNOWN, 2.2: DONE, 2.3: DONE
ruby_2_3 r56722 merged revision(s) 56421,56422.
Related to Bug #9574 : Inconsistent behavior between Kernel#Float and to_f added
Also available in: Atom
PDF
Like 0
Like 0 Like 0 Like 0 Like 0 Like 0 Like 0 Like 0