Actions
Feature #20705
openShould "0.E-9" be a valid float value?
Status:
Open
Assignee:
-
Target version:
-
Description
Ruby doesn't accept "0.E-9" as a valid float value:
$ ruby -e 'Float("0.E-9")'
<internal:kernel>:218:in 'Kernel#Float': invalid value for Float(): "0.E-9" (ArgumentError)
from -e:1:in '<main>'
But other systems accept "0.E-9" as a valid float value:
PostgreSQL:
=> select 0.E-9;
?column?
-------------
0.000000000
(1 row)
MySQL:
> select 0.E-9;
+-------+
| 0.E-9 |
+-------+
| 0 |
+-------+
1 row in set (0.00 sec)
Python:
$ python3 -c 'print(0.E-9)'
0.0
Node.js:
$ nodejs -e 'console.log(0.E-9)'
0
Should Ruby accept "0.E-9" as a valid float value?
FYI: I don't have an opinion of this. I just realized this by an issue from an user of a maintained library by me: https://github.com/apache/arrow/issues/43877
Updated by nobu (Nobuyoshi Nakada) 3 days ago
It feels reasonable to relax the to_f
conversion.
Regarding Python and Node.js examples, they are literals and different things, I think.
Updated by mame (Yusuke Endoh) 3 days ago
Note that they also treat 0.
as a floating point number literal.
$ python3 -c 'print(0.)'
0.0
$ node -e 'console.log(0.)'
0
Updated by Hanmac (Hans Mackowiak) 2 days ago
we need to be careful with this, because while 0.1E-9
is also a valid ruby literal,
0.E-9
is not. (unknown method E for 0)
1E-9
is valid literal again
Actions
Like0
Like0Like1Like0