Project

General

Profile

Actions

Bug #11736

closed

Float(arg) not consistent with documentation

Added by bwheeler96 (Brian Wheeler) almost 9 years ago. Updated about 8 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.5p273
[ruby-core:71661]

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


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #9574: Inconsistent behavior between Kernel#Float and to_fClosedzzak (zzak _)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0