Fix NaN comparison in circle_same test

Commit c4c340088 changed geometric operators to use float4 and float8
functions, and handle NaN's in a better way. The circle sameness test
had a typo in the code which resulted in all comparisons with the left
circle having a NaN radius considered same.

  postgres=# select '<(0,0),NaN>'::circle ~= '<(0,0),1>'::circle;
  ?column?
  ----------
  t
  (1 row)

This fixes the sameness test to consider the radius of both the left
and right circle.

Backpatch to v12 where this was introduced.

Author: Ranier Vilela <ranier.vf@gmail.com>
Discussion: https://postgr.es/m/CAEudQAo8dK=yctg2ZzjJuzV4zgOPBxRU5+Kb+yatFiddtQk6Rw@mail.gmail.com
Backpatch-through: v12
This commit is contained in:
Daniel Gustafsson 2022-09-12 12:59:06 +02:00
parent be0b0528cb
commit 13b8a1c196
2 changed files with 2 additions and 3 deletions

View File

@ -4763,7 +4763,7 @@ circle_same(PG_FUNCTION_ARGS)
CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
PG_RETURN_BOOL(((isnan(circle1->radius) && isnan(circle1->radius)) ||
PG_RETURN_BOOL(((isnan(circle1->radius) && isnan(circle2->radius)) ||
FPeq(circle1->radius, circle2->radius)) &&
point_eq_point(&circle1->center, &circle2->center));
}

View File

@ -4342,9 +4342,8 @@ SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 ~= c2.f1;
<(100,200),10> | <(100,200),10>
<(100,1),115> | <(100,1),115>
<(3,5),0> | <(3,5),0>
<(3,5),NaN> | <(3,5),0>
<(3,5),NaN> | <(3,5),NaN>
(9 rows)
(8 rows)
-- Overlap with circle
SELECT c1.f1, c2.f1 FROM CIRCLE_TBL c1, CIRCLE_TBL c2 WHERE c1.f1 && c2.f1;