[PATCH 1/3] Implement tau() function - Mailing list pgsql-hackers

From Asbjørn Sloth Tønnesen
Subject [PATCH 1/3] Implement tau() function
Date
Msg-id 4eec5487f486c2e245acab50e1aee011f399db7f.1403915555.git.asbjorn@asbjorn.it
Whole thread Raw
In response to [PATCH 0/3] Tau support  (Asbjørn Sloth Tønnesen <asbjorn@asbjorn.it>)
List pgsql-hackers
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




pgsql-hackers by date:

Previous
From: Asbjørn Sloth Tønnesen
Date:
Subject: [PATCH 3/3] earthdistance: TWO_PI => M_TAU
Next
From: Asbjørn Sloth Tønnesen
Date:
Subject: [PATCH 2/3] backend: use M_TAU instead of M_PI