[erlang-questions] erlang float comparison

Angel J. Alvarez Miguel clist@REDACTED
Wed May 16 15:20:09 CEST 2012


Hi

While presenting this "case"  these days we also have changed some other code so 
 (right now) we are.. ah... unable to reproduce such scenario properly,  im rechecking 
the whole thing (i said we dont have any versioning system?) 

Also, asking my workmate about this, results also in some vague memories about acos 
failing on a number around 1.0-e8 still we can detail exactly what the number was.. d'oh

So we stated to log all runs after this fiasco in order to honor with real data our (future) claims...

a few quick checks confirm that you all are right while by all means i must be wrong...

so I must state that there isnt erlang fault nor ieee floats...

...in the end is probably my fault,  we messed up something, i agree it is rather dificult to find 
such values passing the test but failing the acos fun. 

But after all and being unsure about floating point behaviour (its probably the first time I try to work 
on such numerical thing after many years of boring sysadmin shell scripting...) that i wrote this 
on the list....

Sorry for bothering you all, nevertheless, such coverage is one of the things i really appreciate, 
every time the list machinery starts growling, we (me) learn a lot of pretty interesting things..


/Angel


On Miércoles, 16 de Mayo de 2012 00:43:40 usted escribió:
> On 15/05/2012, at 9:04 PM, Angel J. Alvarez Miguel wrote:
> > The problem can be stated as:
> > 
> > Result = case Myfloat > 1.0 of
> > 
> > 	true -> 1.0;
> > 	false MyFloat
> > 	end
> > 
> > ...
> > ...
> > math:acos(Result).
> > 
> > after that  we came across some values that fail to pass the test > 1.0
> > but are seen as greater to the math:acos function rendering a bad
> > arithmetic expression error
> 
> That is pretty astonishing, actually.
> The obvious question is *what are these values*?
> I've just written a test loop searching for such
> values and so far haven't found any.
> 
> Is there any difference between emulated and native code?
> Why aren't you worried about Myfloat < -1.0?
> 
> By the way, this seems a rather strange way to write
> 
> 	Result = if Myfloat > 1.0 -> 1.0 ; true -> Myfloat end
> 
> Do you know what trig library your copy of Erlang was linked
> with?  Here's the relevant code from fdlibm:
> 
>     hx = __HI(x);
>     ix = hx & 0x7fffffff;
>     if (ix >= 0x3ff00000) {     /* |x| >= 1 */
>         if (((ix - 0x3ff00000) | __LO(x)) == 0) {       /* |x|==1 */
>             if (hx > 0)
>                 return 0.0;     /* acos(1) = 0  */
>             else
>                 return pi + 2.0 * pio2_lo;      /* acos(-1)= pi */
>         }
>         return (x - x) / (x - x);       /* acos(|x|>1) is NaN */
>     }
> 
> There's no way _that_ could claim an IEEE double was greater
> than 1.0 if it wasn't.

-- 
-



More information about the erlang-questions mailing list