Hi,
first of all I have to state that I'm aware of the fact that comparing floating point values directly with ==, !=, <, > is a bad idea. But this is a special case ;)
I have the following few lines of code:
if (sqrt(2) != SQRT2) //#define SQRT2 1.4142135 { do something; } return error;
This results to the following lines in the C166 Simulator:
00012A32 E008 MOV R8,#0x00 00012A34 E6F90040 MOV R9,#0x4000 00012A38 CA006E12 CALLA CC_UC,sqrt(0x1126E) 00012A3C E6F6F304 MOV R6,#0x04F3 00012A40 E6F7B53F MOV R7,#0x3FB5 00012A44 CA00B411 CALLA CC_UC,?C_FPCMP(0x111B4) 00012A48 2D01 JMPR CC_Z,0x012A4C 522: do something; 00012A4A E0FD MOV R13,#0x0F 523: } 524: return error; 00012A4C F04D MOV R4,R13
Let us execute this code until "line" 00012A44. At this point R5 (0x3fb5) and R4 (0x04f3) hold the result of the sqrt(2) computation. Registers R7 and R6 have the same values. Now if I change the value of R4 slightly to 0x03f2, FPCMP does not detect the inequality between both register sets. Why is that? Why is FPCMP so complicated? Why does simply comparing both register pairs to each other not work? An inequality is not detected until I change the value of R4 to 0x04EB (downwards) 0x04FB (upwards).
I'm quite sure that this is an intended behavior but I just don't understand why. Would be great, if someone explains it to me.
Thanks in advance!
Cheers Peter