Re: Comparing floating point values in Java
- From: Lew <lew@xxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 12:44:26 -0500
Philipp wrote:
float a = 1;
float b = 1;
Side note: consider explicitly setting float variables to float constants rather than integer constants:
float a = 1.f;
This prevents conversion from being an issue.
Generally you can count on constants comparing equal if they represent the same value. Generally you cannot count on calculated values equaling differently-calculated values even were they mathematically equivalent given infinite precision.
It makes a difference what values you wish to represent. Not all values are precisely representable in limited-precision floating point.
Read
<http://docs.sun.com/source/806-3568/ncg_goldberg.html>
available as a PDF from
<http://www.physics.ohio-state.edu/~dws/grouplinks/floating_point_math.pdf>
among other places.
- Lew
.
- References:
- Comparing floating point values in Java
- From: Philipp
- Comparing floating point values in Java
- Prev by Date: Re: Object reference counting
- Next by Date: Re: Comparing floating point values in Java
- Previous by thread: Comparing floating point values in Java
- Next by thread: Re: Comparing floating point values in Java
- Index(es):
Relevant Pages
|
|