Project

General

Profile

Bug #11736

Float(arg) not consistent with documentation

Added by bwheeler96 (Brian Wheeler) almost 4 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
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

Related to Ruby master - Bug #9574: Inconsistent behavior between Kernel#Float and to_fClosedActions

Associated revisions

Revision 3827c23a
Added by hsbt (Hiroshi SHIBATA) about 3 years ago

  • object.c: Improve documentation for Integer conversion. [ruby-core:71661][Bug #11736][ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 56421
Added by hsbt (Hiroshi SHIBATA) about 3 years ago

  • object.c: Improve documentation for Integer conversion. [ruby-core:71661][Bug #11736][ci skip]

Revision 56421
Added by hsbt (Hiroshi SHIBATA) about 3 years ago

  • object.c: Improve documentation for Integer conversion. [ruby-core:71661][Bug #11736][ci skip]

Revision 56421
Added by hsbt (Hiroshi SHIBATA) about 3 years ago

  • object.c: Improve documentation for Integer conversion. [ruby-core:71661][Bug #11736][ci skip]

Revision 56421
Added by hsbt (Hiroshi SHIBATA) about 3 years ago

  • object.c: Improve documentation for Integer conversion. [ruby-core:71661][Bug #11736][ci skip]

Revision 331fea27
Added by usa (Usaku NAKAMURA) about 3 years ago

merge revision(s) 56421,56422: [Backport #11736]

    * object.c: Improve documentation for Integer conversion.
      [ruby-core:71661][Bug #11736][ci skip]

    * object.c: Improve documentation for Float conversion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@56501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 56501
Added by usa (Usaku NAKAMURA) about 3 years ago

merge revision(s) 56421,56422: [Backport #11736]

* object.c: Improve documentation for Integer conversion.
  [ruby-core:71661][Bug #11736][ci skip]

* object.c: Improve documentation for Float conversion.

Revision 627eec87
Added by nagachika (Tomoyuki Chikanaga) about 3 years ago

merge revision(s) 56421,56422: [Backport #11736]

    * object.c: Improve documentation for Integer conversion.
      [ruby-core:71661][Bug #11736][ci skip]

    * object.c: Improve documentation for Float conversion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@56722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 56722
Added by nagachika (Tomoyuki Chikanaga) about 3 years ago

merge revision(s) 56421,56422: [Backport #11736]

* object.c: Improve documentation for Integer conversion.
  [ruby-core:71661][Bug #11736][ci skip]

* object.c: Improve documentation for Float conversion.

History

Updated by ko1 (Koichi Sasada) almost 4 years ago

  • Description updated (diff)
  • Assignee set to zzak (Zachary Scott)

Document is wrong.
Zack, could you fix it?

Updated by dpulliam (Dylan Pulliam) almost 4 years ago

I have prepared a patch for this. Let me know what you think.

#3

Updated by hsbt (Hiroshi SHIBATA) about 3 years ago

  • Status changed from Open to Closed

Applied in changeset r56421.


  • object.c: Improve documentation for Integer conversion. [ruby-core:71661][Bug #11736][ci skip]

Updated by hsbt (Hiroshi SHIBATA) about 3 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED
  • Assignee changed from zzak (Zachary Scott) to hsbt (Hiroshi SHIBATA)

Updated by usa (Usaku NAKAMURA) about 3 years ago

  • 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.

Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • 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.

#7

Updated by jeremyevans0 (Jeremy Evans) 4 months ago

  • Related to Bug #9574: Inconsistent behavior between Kernel#Float and to_f added

Also available in: Atom PDF