Forums Register Login

float & JQ+ -- VELU

+Pie Number of slices to send: Send
Hi,
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;
System.out.println(f);
System.out.println(f*3.0f);
System.out.println((f*3.0f)==1.0f);//3
}
}
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
+Pie Number of slices to send: Send
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.
Bill
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 604 times.
Similar Threads
Error with JQPlus Question
precision of double and float
Doubt
Marcus Q1
Floating Confusion
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:09:42.