Re: explicitly casting return value of avg() to float4 - Mailing list pgsql-general

From Tom Lane
Subject Re: explicitly casting return value of avg() to float4
Date
Msg-id 4895.1019761431@sss.pgh.pa.us
Whole thread Raw
In response to explicitly casting return value of avg() to float4  (Jon Lapham <lapham@extracta.com.br>)
List pgsql-general
Jon Lapham <lapham@extracta.com.br> writes:
> Is the preferred way to return the average of ::float4 values to
> explicitly cast the returned value of avg() to ::float4?

Yeah, if you want it to float4 precision.  The internal arithmetic
is always done in float8 to try to minimize cancellation problems.

> main_v0_8=# select avg(0.01::float4);
>           avg
> ---------------------
>   0.00999999977648258
> (1 row)

This isn't really any different from

regression=# select 0.01::float4::float8;
       float8
---------------------
 0.00999999977648258
(1 row)


            regards, tom lane

pgsql-general by date:

Previous
From: Neil Conway
Date:
Subject: Re: Performance Issues with count()
Next
From: Grant Johnson
Date:
Subject: Re: Performance Issues with count()