Re: math.e and misc.e
Robert Craig wrote:
>
> Jason Gade wrote:
> > Is it possible to just be able to test for nan or -nan? And maybe to assign
> > nan in Euphoria source?
>
> If you want something interesting to do,
> try setting a Euphoria constant to NaN, and see what
> you can do with it. You might have to use float64_to_atom()
> as you suggested, since things like sqrt(-1) are caught
> by the interpreter. Don't ask me what the bit pattern is.
> Also, I'm not sure how consistent the treatment of NaN is
> across C compilers (e.g. printf()).
>
> Regards,
> Rob Craig
> Rapid Deployment Software
> <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a>
As apparent from Juergen's is_nan() implementation, the bit pattern is:
* all exponent bits set to 1 (so Juergen's function would fail on 80-bit long
doubles, not to mention Motorola 96-bit ones)
* most significant mantissa bit separates between quiet and signalling NaN.
Intel and AMD set this bit for signalling NaNs, and this is the recommended
standard. It may not work on other chips. Quiet NaNs are allowed to propagate,
while signalling NaNs cause FPU exceptions - hence the names.
However, rather than looking for a specific bit pattern, which is likely to have
portability problems - see above -, we can use an intrinsic property. NaNs share
a property which is supposed to hold across all hardware implementations: a NaN
never equals anything, not even itself. As a result, the recommended test for a
NaN is
if x != x then ...
This can be implemented easily using machine code if one doesn't trust the C
compiler, and ensures NaNs are always detected, wile legitimate values don't get
mistaken for a NaN.
CChris
|
Not Categorized, Please Help
|
|