Re: atom = problem?
- Posted by CChris <christian.cuvier at a?ricultur?.gouv.fr> Apr 28, 2008
- 810 views
Jeremy Cowgar wrote: > > Can someone make the following code work? > > }}} <eucode> > include misc.e > > atom a > a = tan(10.5) > pretty_print(1, a, {0}) > printf(1, "\n%.60f\n", a) > > if a = 1.8498999934219273466595723220962099730968475341796875 then > puts(1, "EQUAL\n") > else > puts(1, "NOT EQUAL\n") > end if > </eucode> {{{ > > The result I get here w/3.2 or 3.1.1 is: > > $ exu test.e > 1.849899993 > 1.849899993421927346659572322096209973096847534179687500000000 > NOT EQUAL > > I'm having problems with unit testing because of this. > > Thanks! > > -- > Jeremy Cowgar > <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a> You shouldn't use string conversion to compare atoms, because of the limited precision of floating point numbers in hardware. Use atom_to_float64() in machine.e instead to obtain a sequence of 8 bytes, which is the internal representation of the number. Then comparing these sequences of equal length becomes unambiguous. CChris