This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes float & JQ+ -- VELU Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "float & JQ+ -- VELU" Watch "float & JQ+ -- VELU" New topic

float & JQ+ -- VELU

kaushik banerjee
Ranch Hand

Joined: Mar 11, 2001
Posts: 56
Velu's notes & JQ+ says that line 3 will return false but it returns true when compiling with jdk1.3 . why is it so?
public class vo
public static void main(String[] a)
float f=1.0f/3.0f;
i guess this is because jdk1.2 gives that output. But in the actual exam what should be the correct answer to the question ?
Thx in advance
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
The point is that you can't rely on exact representation of repeating fractions and decimal representations in floating point primitives. Just watch out for assuming that == will always work as you expect after a series of floating point operations.
I agree. Here's the link:
subject: float & JQ+ -- VELU
It's not a secret anymore!