[PATCH 0/3] Tau support

Started by Asbjørn Sloth Tønnesenover 11 years ago7 messages
#1Asbjørn Sloth Tønnesen
asbjorn@asbjorn.it

Hi,

Please see the following patches for implementing support
for and migrating to Tau in PostgreSQL.

Happy Tau Day Hacking
http://tauday.com/

Make sure to check out this shory story:
http://tauday.com/a-parable

Asbjørn Sloth Tønnesen (3):
Implement tau() function
backend: use M_TAU instead of M_PI
earthdistance: TWO_PI => M_TAU

contrib/earthdistance/earthdistance.c | 12 +++++++-----
doc/src/sgml/func.sgml | 13 +++++++++++++
src/backend/utils/adt/float.c | 21 +++++++++++++++++----
src/backend/utils/adt/geo_ops.c | 8 ++++++--
src/include/catalog/pg_proc.h | 2 ++
src/include/utils/builtins.h | 1 +
6 files changed, 46 insertions(+), 11 deletions(-)

--
2.0.0

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Asbjørn Sloth Tønnesen
asbjorn@asbjorn.it
In reply to: Asbjørn Sloth Tønnesen (#1)
[PATCH 1/3] Implement tau() function

Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.it>
---
doc/src/sgml/func.sgml | 13 +++++++++++++
src/backend/utils/adt/float.c | 17 +++++++++++++++--
src/include/catalog/pg_proc.h | 2 ++
src/include/utils/builtins.h | 1 +
4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 551576a..2b48123 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -878,6 +878,19 @@
       <row>
        <entry>
         <indexterm>
+         <primary>tau</primary>
+        </indexterm>
+        <literal><function>tau()</function></literal>
+       </entry>
+       <entry><type>dp</type></entry>
+       <entry><quote>&tau;</quote> constant</entry>
+       <entry><literal>tau()</literal></entry>
+       <entry><literal>6.28318530717959</literal></entry>
+      </row>
+
+      <row>
+       <entry>
+        <indexterm>
          <primary>trunc</primary>
         </indexterm>
         <literal><function>trunc(<type>dp</type> or <type>numeric</type>)</function></literal>
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index 41b3eaa..1278053 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -26,9 +26,12 @@
 #include "utils/sortsupport.h"
+#ifndef M_TAU
+#define M_TAU 6.28318530717958647693
+#endif
+
 #ifndef M_PI
-/* from my RH5.2 gcc math.h file - thomas 2000-04-03 */
-#define M_PI 3.14159265358979323846
+#define M_PI (M_TAU / 2.0)
 #endif

/* Visual C++ etc lacks NAN, and won't accept 0.0/0.0. NAN definition from
@@ -1716,6 +1719,16 @@ dpi(PG_FUNCTION_ARGS)

 /*
+ *		dtau				- returns the constant Tau
+ */
+Datum
+dtau(PG_FUNCTION_ARGS)
+{
+	PG_RETURN_FLOAT8(M_TAU);
+}
+
+
+/*
  *		radians		- returns radians converted from degrees
  */
 Datum
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 0b6105b..4148bed 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -1825,6 +1825,8 @@ DATA(insert OID = 1609 (  radians			PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701
 DESCR("degrees to radians");
 DATA(insert OID = 1610 (  pi				PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 701 "" _null_ _null_ _null_ _null_ dpi _null_ _null_ _null_ ));
 DESCR("PI");
+DATA(insert OID = 1611 (  tau				PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 701 "" _null_ _null_ _null_ _null_ dtau _null_ _null_ _null_ ));
+DESCR("Tau");

DATA(insert OID = 1618 ( interval_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 701" _null_ _null_ _null_ _null_ interval_mul _null_ _null_ _null_ ));

diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index bbb5d39..0258a64 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -408,6 +408,7 @@ extern Datum dsin(PG_FUNCTION_ARGS);
 extern Datum dtan(PG_FUNCTION_ARGS);
 extern Datum degrees(PG_FUNCTION_ARGS);
 extern Datum dpi(PG_FUNCTION_ARGS);
+extern Datum dtau(PG_FUNCTION_ARGS);
 extern Datum radians(PG_FUNCTION_ARGS);
 extern Datum drandom(PG_FUNCTION_ARGS);
 extern Datum setseed(PG_FUNCTION_ARGS);
-- 
2.0.0

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Asbjørn Sloth Tønnesen
asbjorn@asbjorn.it
In reply to: Asbjørn Sloth Tønnesen (#1)
[PATCH 2/3] backend: use M_TAU instead of M_PI

Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.it>
---
src/backend/utils/adt/float.c | 4 ++--
src/backend/utils/adt/geo_ops.c | 8 ++++++--
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index 1278053..b0211f8 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -1701,7 +1701,7 @@ degrees(PG_FUNCTION_ARGS)
 	float8		arg1 = PG_GETARG_FLOAT8(0);
 	float8		result;
-	result = arg1 * (180.0 / M_PI);
+	result = arg1 * (360.0 / M_TAU);

CHECKFLOATVAL(result, isinf(arg1), arg1 == 0);
PG_RETURN_FLOAT8(result);
@@ -1737,7 +1737,7 @@ radians(PG_FUNCTION_ARGS)
float8 arg1 = PG_GETARG_FLOAT8(0);
float8 result;

-	result = arg1 * (M_PI / 180.0);
+	result = arg1 * (M_TAU / 360.0);
 	CHECKFLOATVAL(result, isinf(arg1), arg1 == 0);
 	PG_RETURN_FLOAT8(result);
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 54391fd..429de6d 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -23,8 +23,12 @@
 #include "utils/builtins.h"
 #include "utils/geo_decls.h"
+#ifndef M_TAU
+#define M_TAU 6.28318530717958647693
+#endif
+
 #ifndef M_PI
-#define M_PI 3.14159265358979323846
+#define M_PI (M_TAU / 2.0)
 #endif

@@ -5168,7 +5172,7 @@ circle_poly(PG_FUNCTION_ARGS)
SET_VARSIZE(poly, size);
poly->npts = npts;

-	anglestep = (2.0 * M_PI) / npts;
+	anglestep = M_TAU / npts;

for (i = 0; i < npts; i++)
{
--
2.0.0

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Asbjørn Sloth Tønnesen
asbjorn@asbjorn.it
In reply to: Asbjørn Sloth Tønnesen (#1)
[PATCH 3/3] earthdistance: TWO_PI => M_TAU

Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Asbjørn Sloth Tønnesen (#1)
Re: [PATCH 0/3] Tau support

=?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= <asbjorn@asbjorn.it> writes:

Please see the following patches for implementing support
for and migrating to Tau in PostgreSQL.

While I don't particularly object to adding a tau() function, the rest of
this seems like change for the sake of change. What's the point? And
it had better be a darn good point, because cross-version code differences
are a constant source of maintenance pain for us. We don't need ones
that have no concrete value.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6David Fetter
david@fetter.org
In reply to: Tom Lane (#5)
Re: [PATCH 0/3] Tau support

On Fri, Jun 27, 2014 at 06:03:33PM -0700, Tom Lane wrote:

=?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= <asbjorn@asbjorn.it> writes:

Please see the following patches for implementing support for and
migrating to Tau in PostgreSQL.

While I don't particularly object to adding a tau() function, the
rest of this seems like change for the sake of change. What's the
point? And it had better be a darn good point, because
cross-version code differences are a constant source of maintenance
pain for us. We don't need ones that have no concrete value.

It's Tau day (6.28) in some parts of the world already. Might that be
the cause?

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david.fetter@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#5)
Re: [PATCH 0/3] Tau support

On Fri, Jun 27, 2014 at 9:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

=?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= <asbjorn@asbjorn.it> writes:

Please see the following patches for implementing support
for and migrating to Tau in PostgreSQL.

While I don't particularly object to adding a tau() function, the rest of
this seems like change for the sake of change. What's the point? And
it had better be a darn good point, because cross-version code differences
are a constant source of maintenance pain for us. We don't need ones
that have no concrete value.

Perhaps we should also have a pau() function, as proposed here:

http://xkcd.com/1292/

On a related note, I think we should declare "vi" the officially
favored editor of the PostgreSQL project.

(Note: No, I'm not serious.)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers