From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Wrong results from in_range() tests with infinite offset
Date: Sat, 18 Jul 2020 17:28:52 -0400
Message-ID: <4166230.1595107732@sss.pgh.pa.us> (raw)
In-Reply-To: <3941233.1595081173@sss.pgh.pa.us>
References: <3393130.1594925893@sss.pgh.pa.us>
<3464257.1594936216@sss.pgh.pa.us>
<CAEZATCVXfxCR+2gCSwFMQPfyFUVNzY7U6oHfCfjD1OCCVfWUiQ@mail.gmail.com>
<3506768.1594947597@sss.pgh.pa.us>
<CAEZATCVQO1vUXo0PjHToxvyZ8piwH-u-mTMqMhrGku2dYMhWbw@mail.gmail.com>
<3941233.1595081173@sss.pgh.pa.us>
I wrote:
> Dean Rasheed <dean.a.rasheed@gmail.com> writes:
>> if (isinf(base) && isinf(offset))
>> {
>> if ((base > 0 && sub) || (base < 0 && !sub))
>> PG_RETURN_BOOL(true);
>> }
> Yeah, I'd experimented with more-or-less that logic before arriving at
> my v2 patch. I didn't like the outcome that "inf both infinitely precedes
> and infinitely follows itself". Still, it is nicely simple.
I spent some more time thinking about this, and came to a couple
of conclusions.
First, let's take it as given that we should only special-case
situations where the sum would be computed as NaN. That destroys my
position that, for instance, -inf shouldn't be included in the range
that ends 'inf preceding' itself, because the normal calculation goes
through as -inf <= (-inf - inf) which yields TRUE without forming any
NaN. Although that conclusion seems weird at first glance, there
seems no way to poke a hole in it without rejecting the principle
that inf + inf = inf.
Second, if -inf is included in the range that ends 'inf preceding'
itself, symmetry dictates that it is also included in the range that
begins 'inf following' itself. In that case we'd be trying to compute
-inf >= (-inf + inf) which does involve a NaN, but this argument says
we should return TRUE.
The other three cases where we'd hit NaNs are likewise symmetric with
non-NaN cases that'd return TRUE. Hence, I'm forced to the conclusion
that you've got it right above. I might write the code a little
differently, but const-TRUE-for-NaN-cases seems like the right behavior.
So I withdraw my objection to defining it this way. Unless somebody
else weighs in, I'll commit it like that in a day or two.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, dean.a.rasheed@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Wrong results from in_range() tests with infinite offset
In-Reply-To: <4166230.1595107732@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox