Re: math.e and misc.e
- Posted by Juergen Luethje <j.lue at gmx.??> Aug 06, 2007
- 481 views
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()). I have the following code in my private math library:
global function pos_inf() return 1.8e+307 * 10 -- Positive Infinity value (IEEE 754) end function global function neg_inf() return -pos_inf() -- Negative Infinity value (IEEE 754) end function global function nan() return -(pos_inf()+neg_inf()) -- "Not a Number" value (IEEE 754) -- mulNAN = -(0*pos_inf()) end function -- divNAN = -(pos_inf()/pos_inf())
Jason, if you want to do some "research" you can look in the EUforum archives for this stuff. Previously, I had implemented the values above by assigning them to global constants. But that caused a strange bug which was very hard to find: I had written a DLL that included my private math library, but did not use these global constants. The DLL is a plugin for Total Commander (TC). When trying to _install_ (not even use) this plugin by using the concerning installation routine that is built-in into TC, then TC always crashed. After moving 'pos_inf', 'neg_inf' and 'nan' from global constants to global functions, the problem was gone. Regards, Juergen