[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.3.0 (work1) now available
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Mon, 8 Jul 2013 13:57:11 -0300 (BRT)
Hi Roberto
Suppose I read a large number of values (some integer, some not)
from a text file into a table and then perform extensive
computations on them.
Should I multiply each value by 1.0 (or add 0.0), to pre-convert all
of them to fp, to avoid slowing down the following computations
compared to Lua 5.2?
There are two formats for reading numbers: io.read("*n") always reads
a floating-point number, and io.read("*i") always reads an integer.
Both functions expect a number in the proper format, that is if
you try to read an integer from "2.0" it will return 2, but it won't
consume the ".0". Thus, unless you need only floating-point numbers,
you have to know what you're doing.
So, usually there is no need to convert anything.
No conversions in the mentioned case :-)
Would you provide a "smart" (not a good name, but you know
what I mean :-) format to read a number in whatever format (as "*n")
but return an integer (as "*i") if appropriate?
In fact I don't use anything like that, just a thought :-)
Suppose the file will provide table keys; there would be two conversions:
from file (integer) to number (fp), then from number to key (integer).
Unless I know all numbers are integers and use "*i".
Regards,
Tomás