lua-users home
lua-l archive

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


>From: Reuben Thomas [mailto:rrt@dcs.gla.ac.uk]

>It's up to your system's implementation of floating point, then. It's
>going to be safer to use an integer number type (it's not too hard, the
>relevant post gives step by step instructions), but for most applications
>it shouldn't matter. I've certainly never had problems, but my apps tend
>to be text processing, not numeric.

I've done CPU emulation in off-the-shelf Lua (I needed it fast to write, not
fast to execute).  Lots and lots of integer operations, including boolean
operations (divide&mod to split into a table of bits, then multiply&add to
put it back together).  Every bit had to be correct.  Lua performed
perfectly.

These days, "your system" will implement IEEE 754 floating point.  If your
integers stay within the size of the mantissa, the basic operations (with
one exception) will be exact.  The exception is division - that will often
try to
give you a result that isn't an integer (and usually isn't representable
exactly in floating point).  The integer part will be correct.  Just apply
your favourite rounding method.

http://cch.loria.fr/documentation/IEEE754/ACM/goldberg.pdf
"What Every Computer Scientist Should Know About Floating-Point Arithmetic"
is a very good read.
-Virus scanned and cleared ok