[PATCH 3/3] earthdistance: TWO_PI => M_TAU

From: Asbjørn Sloth Tønnesen <asbjorn(at)asbjorn(dot)it>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Asbjørn Sloth Tønnesen <asbjorn(at)asbjorn(dot)it>
Subject: [PATCH 3/3] earthdistance: TWO_PI => M_TAU
Date: 2014-06-28 00:52:24
Message-ID: 4a062935494c882feda0675bf5d1fa5115754e7c.1403915555.git.asbjorn@asbjorn.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn(at)asbjorn(dot)it>
---
contrib/earthdistance/earthdistance.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/contrib/earthdistance/earthdistance.c b/contrib/earthdistance/earthdistance.c
index 6bbebdf..432309c 100644
--- a/contrib/earthdistance/earthdistance.c
+++ b/contrib/earthdistance/earthdistance.c
@@ -6,16 +6,18 @@

#include "utils/geo_decls.h" /* for Point */

-#ifndef M_PI
-#define M_PI 3.14159265358979323846
+#ifndef M_TAU
+#define M_TAU 6.28318530717958647693
#endif

+#ifndef M_PI
+#define M_PI (M_TAU / 2.0)
+#endif

PG_MODULE_MAGIC;

/* Earth's radius is in statute miles. */
static const double EARTH_RADIUS = 3958.747716;
-static const double TWO_PI = 2.0 * M_PI;


/******************************************************
@@ -30,7 +32,7 @@ static const double TWO_PI = 2.0 * M_PI;
static double
degtorad(double degrees)
{
- return (degrees / 360.0) * TWO_PI;
+ return (degrees / 360.0) * M_TAU;
}

/******************************************************
@@ -67,7 +69,7 @@ geo_distance_internal(Point *pt1, Point *pt2)
/* compute difference in longitudes - want < 180 degrees */
longdiff = fabs(long1 - long2);
if (longdiff > M_PI)
- longdiff = TWO_PI - longdiff;
+ longdiff = M_TAU - longdiff;

sino = sqrt(sin(fabs(lat1 - lat2) / 2.) * sin(fabs(lat1 - lat2) / 2.) +
cos(lat1) * cos(lat2) * sin(longdiff / 2.) * sin(longdiff / 2.));
--
2.0.0

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-06-28 01:03:33 Re: [PATCH 0/3] Tau support
Previous Message Asbjørn Sloth Tønnesen 2014-06-28 00:52:23 [PATCH 2/3] backend: use M_TAU instead of M_PI