Re: numeric and float comparison oddities - Mailing list pgsql-hackers

From Kevin Grittner
Subject Re: numeric and float comparison oddities
Date
Msg-id 1406904656.34054.YahooMailNeo@web122305.mail.ne1.yahoo.com
Whole thread Raw
In response to numeric and float comparison oddities  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: numeric and float comparison oddities
List pgsql-hackers
Jeff Davis <pgsql@j-davis.com> wrote:

> I saw some strange results:
>
> postgres=# select '1.1'::numeric = '1.1'::float8;
> ?column?
> ----------
> t
> (1 row)
>
> postgres=# select '1.1'::numeric = '1.1'::float4;
> ?column?
> ----------
> f
> (1 row)

The part I find strange is that the first one evaluates to true,
since numeric can exactly represent 1.1 and float8 cannot.  It also
seems inconsistent with this:

test=# set extra_float_digits = 3;
SET
test=# select '1.1'::float4;
   float4
------------
 1.10000002
(1 row)

test=# select '1.1'::float8;
       float8
---------------------
 1.10000000000000009
(1 row)

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Bug of pg_receivexlog -v
Next
From: Tom Lane
Date:
Subject: Re: numeric and float comparison oddities