ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: bwheeler96@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:71661] [Ruby trunk - Bug #11736] [Open] Float(arg) not consistent with documentation
Date: Tue, 24 Nov 2015 20:10:15 +0000	[thread overview]
Message-ID: <redmine.issue-11736.20151124201015.78cbd3341ce10c04@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11736.20151124201015@ruby-lang.org

Issue #11736 has been reported by Brian Wheeler.

----------------------------------------
Bug #11736: Float(arg) not consistent with documentation
https://bugs.ruby-lang.org/issues/11736

* Author: Brian Wheeler
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
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




-- 
https://bugs.ruby-lang.org/

       reply	other threads:[~2015-11-24 19:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11736.20151124201015@ruby-lang.org>
2015-11-24 20:10 ` bwheeler96 [this message]
2015-12-07  7:43 ` [ruby-core:71889] [Ruby trunk - Bug #11736] Float(arg) not consistent with documentation ko1
2016-02-09 17:52 ` [ruby-core:73752] [Ruby trunk Bug#11736] " dpulliam_ruby
2016-10-14  9:29 ` [ruby-core:77628] " hsbt
2016-10-27  7:27 ` [ruby-core:77776] " usa
2016-11-11 16:06 ` [ruby-core:78089] " nagachika00

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-11736.20151124201015.78cbd3341ce10c04@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).