Re: nan (was: math.e and misc.e)
- Posted by Jason Gade <jaygade at ya?oo?com> Aug 06, 2007
- 503 views
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.