Re: Strange behavior with polygon and NaN - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Strange behavior with polygon and NaN
Date
Msg-id 290594.1606238981@sss.pgh.pa.us
Whole thread Raw
In response to Re: Strange behavior with polygon and NaN  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Responses Re: Strange behavior with polygon and NaN  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
List pgsql-hackers
Kyotaro Horiguchi <horikyota.ntt@gmail.com> writes:
> At Fri, 20 Nov 2020 15:57:46 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in 
>> I don't much like anything about float8_coef_mul().

> I have the same feeling on the function, but I concluded that
> coefficients and coordinates should be regarded as different things in
> the practical standpoint.

> For example, consider Ax + By + C == 0, if B is 0.0, we can remove the
> second term from the equation, regardless of the value of y, of course
> even if it were inf. that is, The function imitates that kind of
> removals.

Meh --- I can see where you're going with that, but I don't much like it.
I fear that it's as likely to introduce weird behaviors as remove any.

The core of the issue in

> | postgres=# select point(1e+300, 'Infinity') <-> line('{1,0,5}');
> |  ?column? 
> | ----------
> |       NaN

is that we generate the line y = Inf:

(gdb) p tmp
$1 = {A = 0, B = -1, C = inf}

and then try to find the intersection with {1,0,5} (x = -5), but that
calculation involves 0 * Inf so we get NaNs.  It seems reasonable that
the intersection should be (-5,Inf), but I don't think we should try
to force the normal calculation to produce that.  I think we'd be
better off to explicitly special-case vertical and/or horizontal lines
in line_interpt_line.

Actually though ... even if we successfully got that intersection
point, we'd still end up with a NaN distance between (1e300,Inf) and
(-5,Inf), on account of Inf - Inf being NaN.  I think this is correct
and we'd be ill-advised to try to force it to be something else.
Although we pretend that two Infs are equal for purposes such as
sorting, they aren't really, so we should not assume that their
difference is zero.

So that line of thought prompts me to tread *very* carefully when
trying to dodge NaN results.  We need to be certain that we
introduce only logically-defensible special cases.  Something like
float8_coef_mul() seems much more likely to lead us into errors
than away from them.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: PoC/WIP: Extended statistics on expressions
Next
From: Daniil Zakhlystov
Date:
Subject: Re: libpq compression