Re: Incorrect rounding of double values at max precision - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Incorrect rounding of double values at max precision
Date
Msg-id 695837.1603244932@sss.pgh.pa.us
Whole thread Raw
In response to Re: Incorrect rounding of double values at max precision  (Andres Freund <andres@anarazel.de>)
Responses Re: Incorrect rounding of double values at max precision
List pgsql-bugs
[ btw, thanks for finding this thread; I searched for relevant
discussion earlier today and couldn't find it ]

Andres Freund <andres@anarazel.de> writes:
> It seems crazy that we throw away integer precision in the range it's
> guaranteed to be accurate (that's what, −16777216 to 16777216 for
> float4, more than a magnitude larger than this value). It does feel
> different to me that we're throwing away precision that we could know is
> not just the result of floating point imprecision.

Meh.  Yeah, we could improve the observed results for float4 values
that are integers between 1M and 16M, and some similarly-sized band
for float8; but to what end?  The most likely practical result is
just to postpone the user's discovery that they're Doing It Wrong.
If you expect exact answers out of float calculations then you are
going to learn an expensive lesson sooner or later.  Better sooner,
before you've stored even more inexact data that you cannot fix.

> I didn't find much discussion about how we could deal with pg_upgrade
> issues if we were to change the behaviour. Detect indexes involving such
> casts, and mark them as invalid?

For what that's worth, I do not think I buy the argument that
float4_numeric's behavior can't ever be changed because it's marked
immutable.  Compare other recent discussions about what "immutable"
really means; or compare the fact that various text search functions
are marked immutable despite being quite dependent on config files
that we don't even track.  If we think this is actually an improvement
I'd be fine with changing it in a major release, and documenting
that users should reindex any indexes whose semantics are affected
(of which there'd be epsilon in the real world, anyway).  But I'm
not convinced that changing this is doing anything except putting
more lipstick on the pig.  float is imprecise, and we do no one
a service by trying to hide that.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Andres Freund
Date:
Subject: Re: Incorrect rounding of double values at max precision
Next
From: Andres Freund
Date:
Subject: Re: Incorrect rounding of double values at max precision