Skip site navigation (1) Skip section navigation (2)

Re: explicitly casting return value of avg() to float4

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jon Lapham <lapham(at)extracta(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: explicitly casting return value of avg() to float4
Date: 2002-04-25 19:03:51
Message-ID: 4895.1019761431@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-general
Jon Lapham <lapham(at)extracta(dot)com(dot)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

In response to

Responses

pgsql-general by date

Next:From: Neil ConwayDate: 2002-04-25 19:03:53
Subject: Re: Performance Issues with count()
Previous:From: S GrannisDate: 2002-04-25 18:54:40
Subject: Re: Performance Issues with count()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group