Thread: [PATCH 0/3] Tau support

[PATCH 0/3] Tau support

From
Asbjørn Sloth Tønnesen
Date:
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




[PATCH 1/3] Implement tau() function

From
Asbjørn Sloth Tønnesen
Date:
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>τ</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
701DESCR("degreesto 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);externDatum dpi(PG_FUNCTION_ARGS);
 
+extern Datum dtau(PG_FUNCTION_ARGS);extern Datum radians(PG_FUNCTION_ARGS);extern Datum
drandom(PG_FUNCTION_ARGS);externDatum setseed(PG_FUNCTION_ARGS);
 
-- 
2.0.0




[PATCH 2/3] backend: use M_TAU instead of M_PI

From
Asbjørn Sloth Tønnesen
Date:
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




Re: [PATCH 0/3] Tau support

From
Tom Lane
Date:
Asbjørn Sloth Tønnesen <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



Re: [PATCH 0/3] Tau support

From
David Fetter
Date:
On Fri, Jun 27, 2014 at 06:03:33PM -0700, Tom Lane wrote:
> Asbjørn Sloth Tønnesen <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



Re: [PATCH 0/3] Tau support

From
Robert Haas
Date:
On Fri, Jun 27, 2014 at 9:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Asbjørn Sloth Tønnesen <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