round returns -0

Started by Tony Dareabout 13 years ago3 messagesgeneral
Jump to latest
#1Tony Dare
wadedare4703@comcast.net

I'm taking an standard deviation of a population and subtracting it from
the average of the same population and rounding the result. Sometimes
that result is negative and rounding it returns (or shows up as) a
negative zero (-0) in a SELECT.

basically:
SELECT
client_name, avg(rpt_cnt),
stddev_pop(rpt_cnt),
round(avg(rpt_cnt) - stddev_pop(rpt_cnt))
from client_counts
group by client_name

and what I sometimes get is :
client_name | a dp number | a dp number | -0

In postgresql-world, is -0 = 0? Can I use that negative 0 in further
calculations without fear? Is this a bug?

pg version is 9.2
OS is Windows 2003.

Thanks,

Wade Dare
"Committed to striving for an effort to try..."

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2François Beausoleil
francois@teksol.info
In reply to: Tony Dare (#1)
Re: round returns -0

Le 2013-03-06 à 21:42, Tony Dare a écrit :

I'm taking an standard deviation of a population and subtracting it from the average of the same population and rounding the result. Sometimes that result is negative and rounding it returns (or shows up as) a negative zero (-0) in a SELECT.

basically:
SELECT
client_name, avg(rpt_cnt),
stddev_pop(rpt_cnt),
round(avg(rpt_cnt) - stddev_pop(rpt_cnt))
from client_counts
group by client_name

and what I sometimes get is :
client_name | a dp number | a dp number | -0

In postgresql-world, is -0 = 0? Can I use that negative 0 in further calculations without fear? Is this a bug?

This is related to the recent discussion of floating point values on this mailing list. You can read more about IEEE 754 and whether 0 == -0 on Wikipedia: https://en.wikipedia.org/wiki/Signed_zero#Comparisons

According to that article, IEEE 754 specifies that 0 == -0 in Java/C/etc.

Hope that helps!
François Beausoleil

Attachments:

smime.p7sapplication/pkcs7-signature; name=smime.p7sDownload
#3Tony Dare
wadedare4703@comcast.net
In reply to: François Beausoleil (#2)
Re: round returns -0

On 03/06/2013 07:16 PM, Fran�ois Beausoleil wrote:

Le 2013-03-06 � 21:42, Tony Dare a �crit :

I'm taking an standard deviation of a population and subtracting it from the average of the same population and rounding the result. Sometimes that result is negative and rounding it returns (or shows up as) a negative zero (-0) in a SELECT.

basically:
SELECT
client_name, avg(rpt_cnt),
stddev_pop(rpt_cnt),
round(avg(rpt_cnt) - stddev_pop(rpt_cnt))
from client_counts
group by client_name

and what I sometimes get is :
client_name | a dp number | a dp number | -0

In postgresql-world, is -0 = 0? Can I use that negative 0 in further calculations without fear? Is this a bug?

This is related to the recent discussion of floating point values on this mailing list. You can read more about IEEE 754 and whether 0 == -0 on Wikipedia: https://en.wikipedia.org/wiki/Signed_zero#Comparisons

According to that article, IEEE 754 specifies that 0 == -0 in Java/C/etc.

Hope that helps!
Fran�ois Beausoleil

This is happening in a plpgsql function, so I guess that makes it C,
under the hood. That does help, thank you.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general