Re: The 85/0.0085 mistery ?

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: fwr(at)ga(dot)prestige(dot)net, "'Jean-Christophe Pazzaglia'" <jc(dot)pazzaglia(at)albourne(dot)com>, "'PostgreSQL-development'" <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: The 85/0.0085 mistery ?
Date: 2000-10-06 14:23:19
Message-ID: 39DDE057.F274CDA4@tm.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
>
> "Frederick W. Reimer" <fwr(at)ga(dot)prestige(dot)net> writes:
> > In general, it's recommended you don't check for exact equivalence when
> > doing calculations on real numbers and instead check for "almost exactness."
>

perhaps "where trunc(85/0.0085) = 10000" works better.

> Or use datatype NUMERIC, which behaves in a more intuitive way (at least
> for people who are accustomed to thinking in decimal). But yes, exact
> equality checks on float values are usually foolish.

But ...

hannu=# create table ntest(n numeric(3), n1 numeric(6,4));
CREATE
hannu=# insert into ntest values(80, 80/10000);
INSERT 311338 1
hannu=# insert into ntest values(81, 81/10000);
INSERT 311339 1
hannu=# select count(*) from ntest where n/n1 = 10000;
ERROR: division by zero on numeric
hannu=# select * from ntest;
n | n1
----+--------
80 | 0.0000
81 | 0.0000

eek !

I understand why this is so, but should it be ?

Can't we assume that 80/10000 is numeric and back-propagate that
knowledge to constituents so that 80 and 10000 are also considered
numetics.

Or even better assume that 80/10000 is a rational number ;)

-------------------
Hannu

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2000-10-06 14:36:30 Re: The 85/0.0085 mistery ?
Previous Message Cameron Laird 2000-10-06 14:20:41 Ned Lilly available for questioning