From: Sam S. <sd...@gn...> - 2010-08-03 13:42:18
|
Bruno, Bruno Haible wrote: > > >> I still think that it is wrong to roundtrip through lisp when I am >> comparing C integers with C floats, so the correct expression is >> >> if (elt2.machine_float != elt1) goto no; > > This expression will not work. CPUs have no instructions for comparing > a single-float with an uint32. The compiler will either turn this > expression into > ((uint32)elt2.machine_float != elt1) > or into (elt2.machine_float != (float)elt1) the latter is what C does. > In the first case, it produces the wrong result when elt2 is >= 2^32 > and elt1 is 2^32-1 or 2^31-1. In the second case, it produces wrong > results when elt2 = 2^30 and elt1 = 2^30 + 1. this is fine. [1]> (setq a (ash 1 30)) 1073741824 [2]> (1+ (float a)) 1.0737418E9 [3]> (= (float a) (1+ (float a))) T [4]> (= a (1+ (float a))) T [5]> (equalp a (1+ (float a))) T i.e., returning T is correct. (elt2.machine_float != (float)elt1) is exactly what I meant. (and that's what C does). |