Re: 'real' strange problem in 7.1.3 - Mailing list pgsql-hackers

From Knut Forkalsrud
Subject Re: 'real' strange problem in 7.1.3
Date
Msg-id lzlmhfsdm9.fsf@darkstar.cj.com
Whole thread Raw
In response to 'real' strange problem in 7.1.3  (reina@nsi.edu (Tony Reina))
List pgsql-hackers
reina@nsi.edu (Tony Reina) writes:

> db02=# select distinct arm from ellipse where exag_ratio = 1.0;
You never want to use the = test on floating point numbers.  Two
apparently equal numbers may differ in the least significant digit.
The behavior will be close to random.

When you convert the floating point to a string and round off to a
specific number of digits, you can use string compare to get more
predictable results.

Another possibility is to do something like 
  where abs(exag_ratio - 1.0) > 0.000001

(I'm not sure about the SQL function for absolute value, but you get
the idea).

-Knut

-- 
The early worm gets the bird.


pgsql-hackers by date:

Previous
From: Oleg Bartunov
Date:
Subject: aggregate functions for inet ?
Next
From: Tom Lane
Date:
Subject: Re: Quick question