Comparing floating point values in Java
- From: Philipp <sicsicsic@xxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 18:14:40 +0100
Hello,
I'm aware of problems (rounding, NaN etc) when comparing floating point values in computers.
In C++ this goes a bit further as you cannot compare with certitude floating point numbers even if you have made exactly the same operations on each of them (see eg: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.18 )
My question: In Java, will unchanged values compare strictly true if equal?
Is it _guaranteed_ that the following code does output "true" on all JVMs?
Thanks for answers. Phil
example code:
public class Test {
public static void main(String[] args) {
float a = 1;
float b = 1;
System.out.println("a == b?: " + (a == b));
}
}
.
- Follow-Ups:
- Re: Comparing floating point values in Java
- From: Patricia Shanahan
- Re: Comparing floating point values in Java
- From: Arne Vajhøj
- Re: Comparing floating point values in Java
- From: Daniel Pitts
- Re: Comparing floating point values in Java
- From: Thomas Schodt
- Re: Comparing floating point values in Java
- From: Lew
- Re: Comparing floating point values in Java
- Prev by Date: Re: newbie: which IDE to choose?
- Next by Date: Re: Object reference counting
- Previous by thread: newbie: which IDE to choose?
- Next by thread: Re: Comparing floating point values in Java
- Index(es):
Relevant Pages
|
|