[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: lua_newthread etc.**
**From**: Juergen Fuhrmann <fuhrmann@...>
**Date**: Thu, 23 Jan 2003 10:41:35 +0100 (MET)

Hello,
Sorry, but I need to correct one point here...
> Wed, 22 Jan 2003 15:16:27 -0200
> Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
>
[...]
>
> On the other hand, I do have a draft IEEE math library that I'll probably
> distribute when Lua 5.0 final is released. It's pretty simple anyway.
>
> Finally, you can write those in Lua:
>
> function isnan(x) return x~=x end
> function isinfinity(x) return x+1==x end
which mathematically would be right, but numerically would be wrong.
By this, you would get something like the inverse of the machine
epsilon which is defined as the smallest number for which
1+eps > 1
in the floating point arithmetic. In ANSI C, this is exactly
DBL_EPSILON resp. FLT_EPSILON, which for IEEE have the values
2.2204460492503131e-16 resp. 1.19209290e-07.
If the IEEE rules (which I don't know well) 1.79769313486231570e+308
would state that
infinity>x
for all floating point numbers, we could use something like
function isinfinity(x) return x>DBL_MAX end
where DBL_MAX takes the value 1.79769313486231570e+308 in float.h.
But please don't enter this value from within Lua, as there is at
least some danger that sscanf will mess up the value. Rather, it
should be entered using lua_pushvalue from within C to get the exact
valu.
Perhaps it was a wise decision by the ANSI commitee not to include
this stuff into ANSI C because on many systems, this functionality can
be toggled via assembler statements or environment
variables. E.g. many numerical anlaysts rather like to generate
exceptions on 1/0 than checking for infinity or nan, and switch these
feature off. On VAXen, you have floating numbers not covered by IEEE.
Juergen Fuhrmann