Version française
Home     About     Download     Resources     Contact us    
Browse thread
Float literals
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Robert Roessler <roessler@r...>
Subject: Re: [Caml-list] Float literals
Edgar Friendly wrote:
> 1e6       (* an integer?  no, a float without a .  Problem.*)
> 13        (* valid as a float, according to the above definition *)
> 
> Does anyone else find the last two cases kind of odd?  Maybe it's not a
> big deal because the 1e6 is scientific notation, which is float-y, and
> the last one is always parsed as an integer, I assume because of
> precedence in the lexing functions.

There isn't (to me) anything weird about this... from 6.1 in the 
reference manual on "Floating-point literals":

"The decimal part or the exponent part can be omitted, but not both to 
avoid ambiguity with integer literals."

And, as you suggest, in practice it isn't an issue either - a lexer 
will try to see a numeric literal as an int as long as it legally 
still can constitute an int.  But assuming we are still recognizing a 
base 10 literal, a *letter* that isn't 'l', 'L', or 'n' had better be 
an 'e' or 'E' (so that it may still be a float)... or you have an 
invalid token. ;)

Robert Roessler
roessler@rftp.com
http://www.rftp.com