Re: nan (was: math.e and misc.e)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> Jason Gade wrote:
> 
> > Bernie Ryan wrote:
> >
> >> I think the floating point hardware will return NaN.
> > 
> > Yes, but NAN can be more than one value, as can inf. Right now I have a
> > working
> > type definition for isnan(x) and I'll also do one for isinf(x). The names
> > can
> > be changed, of course.
> 
> This is the isnan() function which I wrote some years ago:
> }}}
<eucode>
> global function isnan (object x)
>    -- return TRUE, if and only if x is an IEEE 754 NaN value
>    sequence bits, mantissa
>    integer exponent
> 
>    if sequence(x) then return FALSE end if
> 
>    bits = atom_to_bits64(x)
> 
>    -- check exponent and mantissa
>    exponent = bits_to_int(bits[53..63]) - 1023
>    if exponent = 1024 then
>       mantissa = bits[1..52]
>       if not equal(mantissa, repeat(0,52)) then
>          return TRUE
>       end if
>    end if
>    return FALSE
> end function
> </eucode>
{{{

> 
> Regards,
>    Juergen

Thanks, Juergen. That's a nice implementation. Of course, you would have to have
atom_to_bits64() defined somewhere...

Will stuff like this work for what has been discussed, with regards to error
values?

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu