Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / February 2004

Tip: Looking for answers? Try searching our database.

Question about fcmpg & fcmpl

Thread view: 
My name - 08 Feb 2004 12:11 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.