[PATCH 1/3] Implement tau() function

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 1/3] Implement tau() function
Date: 2014-06-28 00:52:22
Message-ID: 4eec5487f486c2e245acab50e1aee011f399db7f.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>
---
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

In response to

Browse pgsql-hackers by date

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