lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 	Anyway, since tostring() in Lua 5.3 will produce different
> string representations for integer and floating-point numbers (can I
> assume that?) it won't be more useful to have "*i" format to read "1.0"
> and convert it to the integer 1 ?

Useful to whom? If I am reading a list of integer numbers, probably I
do not want to accept 1.0.

The main (only?) reason why Lua has *n for reading is for performance,
to avoid creating an intermediate string for each number it reads.
Anything smarter than fscanf("%lld") or similar will have some impact on
performance, not to mention that the implementation is tricky.  We have
to read the entire numeral as a string, to see whether it is a float or
an integer, and then do the conversion. We must be very careful not to
read too much in cases such as 1.0e-x (must stop before the 'e-x') and
other strange cases.

Any reading option will never be smart enough to guess (and do)
exaclty what we want. (Do we want to accept 1.0 or only 1? What
about 1.1, should it be accepted and rounded? What about hexa-decimal
formats? Scientific notation?) There are too many variations. Sometimes
we have to write code...

-- Roberto