From: | François Beausoleil <francois(at)teksol(dot)info> |
---|---|
To: | Tony Dare <wadedare4703(at)comcast(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: round returns -0 |
Date: | 2013-03-07 03:16:37 |
Message-ID: | 3AB819D5-B2BE-442A-8F54-98F5C108D177@teksol.info |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | MURAT KOÇ | 2013-03-07 11:10:04 | Password Security Standarts on PostgreSQL |
Previous Message | Ian Pilcher | 2013-03-07 03:16:19 | Trust intermediate CA for client certificates |