Issue #5294 has been updated by Yui NARUSE.


Nobuyoshi Nakada wrote:
> Decimal point without fragment part is invalid in Ruby.

It is because 9.E+20 is parsed as 9.E() + 20.
9: Fixnum
E: a method named "E"
+: a method plus
20: Fixnum
----------------------------------------
Bug #5294: to_f does not convert floating point number the same as Fortran
http://redmine.ruby-lang.org/issues/5294

Author: Todd Kushner
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: 1.9.2p180 (2011-02-18) [i386-mingw32]


We were converting some Fortran programs to Ruby, and found the following floating point number format did not convert as Fortran does on input, i.e., on:

'[+-]nn.E[+-]nn'

the exponent is ignored by to_f, but not by Fortran:  

string: '9.E+20    ' float:                        9.0000000000000000000000000
string: '+9.E+20   ' float:                        9.0000000000000000000000000
string: '-9.E+20   ' float:                       -9.0000000000000000000000000
string: '9.E20     ' float:                        9.0000000000000000000000000
string: '+9.E20    ' float:                        9.0000000000000000000000000
string: '-9.E20    ' float:                       -9.0000000000000000000000000
string: '9.E-20    ' float:                        9.0000000000000000000000000
string: '+9.E-20   ' float:                        9.0000000000000000000000000
string: '-9.E-20   ' float:                       -9.0000000000000000000000000

Listed below, we found all other variations we could think of seemed to work properly:

string: '0.9E+21   ' float:    900000000000000000000.0000000000000000000000000
string: '+0.9E+21  ' float:    900000000000000000000.0000000000000000000000000
string: '-0.9E+21  ' float:   -900000000000000000000.0000000000000000000000000
string: '.9E+21    ' float:    900000000000000000000.0000000000000000000000000
string: '+.9E+21   ' float:    900000000000000000000.0000000000000000000000000
string: '-.9E+21   ' float:   -900000000000000000000.0000000000000000000000000
string: '9E+20     ' float:    900000000000000000000.0000000000000000000000000
string: '+9E+20    ' float:    900000000000000000000.0000000000000000000000000
string: '-9E+20    ' float:   -900000000000000000000.0000000000000000000000000
string: '9.0E+20   ' float:    900000000000000000000.0000000000000000000000000
string: '+9.0E+20  ' float:    900000000000000000000.0000000000000000000000000
string: '-9.0E+20  ' float:   -900000000000000000000.0000000000000000000000000
string: '0.9E21    ' float:    900000000000000000000.0000000000000000000000000
string: '+0.9E21   ' float:    900000000000000000000.0000000000000000000000000
string: '-0.9E21   ' float:   -900000000000000000000.0000000000000000000000000
string: '.9E21     ' float:    900000000000000000000.0000000000000000000000000
string: '+.9E21    ' float:    900000000000000000000.0000000000000000000000000
string: '-.9E21    ' float:   -900000000000000000000.0000000000000000000000000
string: '9E20      ' float:    900000000000000000000.0000000000000000000000000
string: '+9E20     ' float:    900000000000000000000.0000000000000000000000000
string: '-9E20     ' float:   -900000000000000000000.0000000000000000000000000
string: '9.0E20    ' float:    900000000000000000000.0000000000000000000000000
string: '+9.0E20   ' float:    900000000000000000000.0000000000000000000000000
string: '-9.0E20   ' float:   -900000000000000000000.0000000000000000000000000
string: '0.9E-19   ' float:                        0.0000000000000000000900000
string: '+0.9E-19  ' float:                        0.0000000000000000000900000
string: '-0.9E-19  ' float:                       -0.0000000000000000000900000
string: '.9E-19    ' float:                        0.0000000000000000000900000
string: '+.9E-19   ' float:                        0.0000000000000000000900000
string: '-.9E-19   ' float:                       -0.0000000000000000000900000
string: '9E-20     ' float:                        0.0000000000000000000900000
string: '+9E-20    ' float:                        0.0000000000000000000900000
string: '-9E-20    ' float:                       -0.0000000000000000000900000
string: '9.0E-20   ' float:                        0.0000000000000000000900000
string: '+9.0E-20  ' float:                        0.0000000000000000000900000
string: '-9.0E-20  ' float:                       -0.0000000000000000000900000

Thanks!

Todd Kushner
Jeppesen
todd.kushner / jeppesen.com



-- 
http://redmine.ruby-lang.org