Re: different results with different compiler settings
> My understanding is that optimization settings do not change
> the result of a correct program.
I can speak only from my small knowledge. Some optimization settings do change the result of a program. One being the directive fixnum-safety. When fixnum-safety is 'off', the compiler starts to be clever and tries to optimize numeric computations as being done on fixnums. In your case, float point is treated as fixnum in the second example.
To see that, try to use (disassable). With the first example, we have something like this for the comparison parts (if I got it correctly):
L13: 323: FF7508 push [ebp+8]
326: 8B45FC move eax, [ebp-4]
329: E88AEF0700 call 201187E2 ; #<Function SYSTEM::*%=$ANY-STUB 201187E2>
L11: 237: FF7508 push [ebp+8]
240: 8B45FC move eax, [ebp-4]
243: E820EF0700 call 20118722 ; #<Function SYSTEM::*%<=$ANY-STUB 20118722>
For the second example something like this (if I got it correctly):
L7: 127: 8B7DF4 move edi, [ebp-C]
130: 397D08 cmp [ebp+8], edi
133: 7F25 jg L9
135: 8B7DF4 move edi, [ebp-C]
138: 397D08 cmp [ebp+8], edi
141: 754E jne L11
As you can see the first example compares values with regard of their types, the second treats all values as fixnums. But the second is fast (less overhead).
> So the program is incorrect, but I don't see it.
Program is correct. It is just the optimization that sometimes is like a voodoo magic :))
Best,
Art