Re: Divide a float4 by 1 - what is going on??????? - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Divide a float4 by 1 - what is going on???????
Date
Msg-id 20050917004314.GA2817@winnie.fuhr.org
Whole thread Raw
In response to Divide a float4 by 1 - what is going on???????  (Daniel Schuchardt <daniel_schuchardt@web.de>)
List pgsql-general
On Sat, Sep 17, 2005 at 02:12:45AM +0200, Daniel Schuchardt wrote:
> CIMSOFT=# SELECT n1/1 FROM test;
>     ?column?
> ------------------
> 2.45667695999146
> (1 row)
>
> Why I get so many digits by a division with one? Anybody should have
> learned that everything / 1 = everything ;-)

Looks like the division is being done in double precision (float8)
and you're seeing the effects of an inexact representation.

test=> SELECT 2.456677::real / 1;
     ?column?
------------------
 2.45667695999146
(1 row)

test=> SELECT 2.456677::real / 1::real;
 ?column?
----------
  2.45668
(1 row)

--
Michael Fuhr

pgsql-general by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: Divide a float4 by 1 - what is going on???????
Next
From: Bill Moseley
Date:
Subject: Re: Setting WHERE on a VIEW with aggregate function.