00.01.class" error?


#1

Hi,

0.1.class results in float.
00.1.class results in error?


SyntaxError: compile error
(irb):5: no . floating literal anymore; put 0 before dot
00.1class
^
(irb):5: syntax error
00.1class
^
from (irb):5


as humans ignore any number of zeros before. why did ruby compiler
concerned abt it?. why this?. needs a fix to compiler :stuck_out_tongue:

sharma


#2

On Feb 24, 2007, at 2:33 PM, Sharma C. wrote:

00.1class
^
from (irb):5


as humans ignore any number of zeros before. why did ruby compiler
concerned abt it?. why this?. needs a fix to compiler :stuck_out_tongue:

I think the problem is that floating point literals must be written
in base 10, unlike integer literals which can be written in octal.
In your case:

00.1.class

the parser sees β€œ00” as as 0 written as an octal constant. The parser
doesn’t consider it as the start of a floating point value because
floating point values must be written in decimal. So after parsing
the β€œ00” as an integer literal it sees β€œ.1” as a no longer supported
floating point literal and complains.

Gary W.