Skip to content

Commit c2b716a

Browse files
committed
Replace imprecise value of PI with a better one, and tweak circle_poly
in hopes of reducing platform-to-platform variations in its results. This will cause the geometry regression test to start failing on some platforms. I plan to update the test later today.
1 parent cea5388 commit c2b716a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/backend/utils/adt/geo_ops.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.67 2002/11/08 17:37:52 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.68 2002/11/08 18:32:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,10 +22,12 @@
2222
#include "utils/builtins.h"
2323
#include "utils/geo_decls.h"
2424

25-
#ifndef PI
26-
#define PI 3.1415926536
25+
#ifndef M_PI
26+
/* from my RH5.2 gcc math.h file - thomas 2000-04-03 */
27+
#define M_PI 3.14159265358979323846
2728
#endif
2829

30+
2931
/*
3032
* Internal routines
3133
*/
@@ -4365,7 +4367,7 @@ circle_center(PG_FUNCTION_ARGS)
43654367
static double
43664368
circle_ar(CIRCLE *circle)
43674369
{
4368-
return PI * (circle->radius * circle->radius);
4370+
return M_PI * (circle->radius * circle->radius);
43694371
}
43704372

43714373

@@ -4438,6 +4440,7 @@ circle_poly(PG_FUNCTION_ARGS)
44384440
size;
44394441
int i;
44404442
double angle;
4443+
double anglestep;
44414444

44424445
if (FPzero(circle->radius) || (npts < 2))
44434446
elog(ERROR, "Unable to convert circle to polygon");
@@ -4455,9 +4458,11 @@ circle_poly(PG_FUNCTION_ARGS)
44554458
poly->size = size;
44564459
poly->npts = npts;
44574460

4461+
anglestep = (2.0 * M_PI) / npts;
4462+
44584463
for (i = 0; i < npts; i++)
44594464
{
4460-
angle = i * (2 * PI / npts);
4465+
angle = i * anglestep;
44614466
poly->p[i].x = circle->center.x - (circle->radius * cos(angle));
44624467
poly->p[i].y = circle->center.y + (circle->radius * sin(angle));
44634468
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy