Hi,
this time I don't have a bug report on Oolong but just simple questions
on two opcodes of the JVM: fcmpg and fcmpl.
In fact, I'm not sure I understand them right.
When I consult the VM Specs (on Sun's site), it says that these two
instructions provide a way to compare two float and that they have an
inverse behaviour with NaN because NaN is unordered.
Until now, everything seems clear. But, I have two questions about that:
1/ Does it mean, that each time I want to translate an expression written
in Java, I have to choose which opcode is appropriate ?
In the VMSpecs, they give this example:
if (d < 100.0) -- use dcmpg
if (d > 100.0) -- use dcmpl
So, if I had used dcmpg in the previous example, the code would be false
when compared to NaN. Right ?
But then, which instruction should I use if I compare two variables ?
(and not a variable with a constant) like this: if (d1 > d2)
That was the easy question ;) Now an even easier question:
2/ What about comparing two NaN numbers ?
Which opcode should I use ?
Comparing two NaN numbers should also always return false, right ?
Thanks in advance for your answers.
Boudewijn Dijkstra - 08 Feb 2004 15:11 GMT
> Hi,
>
[quoted text clipped - 10 lines]
> 1/ Does it mean, that each time I want to translate an expression written
> in Java, I have to choose which opcode is appropriate ?
Yes. That is the task of any compiler.
> In the VMSpecs, they give this example:
> if (d < 100.0) -- use dcmpg
> if (d > 100.0) -- use dcmpl
>
> So, if I had used dcmpg in the previous example, the code would be false
> when compared to NaN. Right ?
*Any* floating point comparison should return false when at least one side
results in a NaN. The compiler should make sure of that.
> But then, which instruction should I use if I compare two variables ?
> (and not a variable with a constant) like this: if (d1 > d2)
It doesn't matter, as long as the code is compiled correctly.
> That was the easy question ;) Now an even easier question:
>
> 2/ What about comparing two NaN numbers ?
> Which opcode should I use ?
None, because that is pointless: it always should return false.
> Comparing two NaN numbers should also always return false, right ?
See above.
glen herrmannsfeldt - 09 Feb 2004 02:09 GMT
> this time I don't have a bug report on Oolong but just simple questions
> on two opcodes of the JVM: fcmpg and fcmpl.
> In fact, I'm not sure I understand them right.
> When I consult the VM Specs (on Sun's site), it says that these two
[quoted text clipped - 12 lines]
> So, if I had used dcmpg in the previous example, the code would be false
> when compared to NaN. Right ?
I believe the important distinction is that,
because NaNs are possible, that
if( d < 100.0) is NOT the same as
if(! (d>=100.0))
-- glen