C23 added trigonometric math functions that act on half-revolutions.
Implement them in C.

Reduce the input argument of `sinpi?` and `tanpi?` to the interval [-1, +1]
before passing the actual calculation on to `sin?` or `tan?`, respectively.
Reduce the input argument of `cospi?` to the interval [0, 2] before passing
the calculation on to `cos?`.

For `acospi?`, `asinpi?`, `atanpi?`, and `atan2pi?`, pass the actual
calculation on to `acos?`, `asin?`, `atan?`, or `atan2?`, respectively,
without any domain reduction.


It's been a while since I last touched anything in mingw-w64. I hope this is
the right way to add these functions. Please, let me know if something needs to
change.
From 6900674268c65300f9acc735d005dbe5ee7221eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Markus=20M=C3=BCtzel?= <[email protected]>
Date: Thu, 8 Jan 2026 15:28:02 +0100
Subject: [PATCH] crt: Implement trigonometric functions on half-revolutions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

C23 added trigonometric math functions that act on half-revolutions.
Implement them in C.

Reduce the input argument of `sinpi?` and `tanpi?` to the interval [-1, +1]
before passing the actual calculation on to `sin?` or `tan?`, respectively.
Reduce the input argument of `cospi?` to the interval [0, 2] before passing
the calculation on to `cos?`.

For `acospi?`, `asinpi?`, `atanpi?`, and `atan2pi?`, pass the actual
calculation on to `acos?`, `asin?`, `atan?`, or `atan2?`, respectively,
without any domain reduction.

Signed-off-by: Markus Mützel <[email protected]>
---
 mingw-w64-crt/Makefile.am    |   1 +
 mingw-w64-crt/math/trigpi.c  | 111 +++++++++++++++++++++++++++++++++++
 mingw-w64-headers/crt/math.h |  37 ++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 mingw-w64-crt/math/trigpi.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index ff032f953..1a79b9054 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -429,6 +429,7 @@ src_ucrtbase=\
   misc/ucrt_mbsinit.c \
   misc/ucrt_tzset.c \
   math/_huge.c \
+  math/trigpi.c \
   misc/__badioinfo.c \
   misc/__p___initenv.c \
   misc/__p___winitenv.c \
diff --git a/mingw-w64-crt/math/trigpi.c b/mingw-w64-crt/math/trigpi.c
new file mode 100644
index 000000000..546ee5131
--- /dev/null
+++ b/mingw-w64-crt/math/trigpi.c
@@ -0,0 +1,111 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+double __cdecl acospi(double x)
+{
+    return acos(x)/M_PI;
+}
+float __cdecl acospif(float x)
+{
+    return acosf(x)/M_PI;
+}
+long double __cdecl acospil(long double x)
+{
+    return acosl(x)/M_PI;
+}
+
+double __cdecl asinpi(double x)
+{
+    return asin(x)/M_PI;
+}
+float __cdecl asinpif(float x)
+{
+    return asinf(x)/M_PI;
+}
+long double __cdecl asinpil(long double x)
+{
+    return asinl(x)/M_PI;
+}
+
+double __cdecl atanpi(double x)
+{
+    return atan(x)/M_PI;
+}
+float __cdecl atanpif(float x)
+{
+    return atanf(x)/M_PI;
+}
+long double __cdecl atanpil(long double x)
+{
+    return atanl(x)/M_PI;
+}
+
+double __cdecl atan2pi(double x, double y)
+{
+    return atan2(x, y)/M_PI;
+}
+float __cdecl atan2pif(float x, float y)
+{
+    return atan2f(x, y)/M_PI;
+}
+long double __cdecl atan2pil(long double x, long double y)
+{
+    return atan2l(x, y)/M_PI;
+}
+
+double __cdecl cospi(double x)
+{
+    x = fmod(x, 2.0);
+    return cos(x*M_PI);
+}
+float __cdecl cospif(float x)
+{
+    x = fmodf(x, 2.0F);
+    return cosf(x*M_PI);
+}
+long double __cdecl cospil(long double x)
+{
+    x = fmodl(x, 2.0L);
+    return cosl(x*M_PI);
+}
+
+double __cdecl sinpi(double x)
+{
+    x = remainder(x, 2.0);
+    return sin(x*M_PI);
+}
+float __cdecl sinpif(float x)
+{
+    x = remainderf(x, 2.0F);
+    return sinf(x*M_PI);
+}
+long double __cdecl sinpil(long double x)
+{
+    x = remainderl(x, 2.0L);
+    return sinl(x*M_PI);
+}
+
+double __cdecl tanpi(double x)
+{
+    x = remainder(x, 2.0);
+    return tan(x*M_PI);
+}
+float __cdecl tanpif(float x)
+{
+    x = remainderf(x, 2.0F);
+    return tanf(x*M_PI);
+}
+long double __cdecl tanpil(long double x)
+{
+    x = remainderl(x, 2.0L);
+    return tanl(x*M_PI);
+}
diff --git a/mingw-w64-headers/crt/math.h b/mingw-w64-headers/crt/math.h
index b5ddf940b..26a1b4af7 100644
--- a/mingw-w64-headers/crt/math.h
+++ b/mingw-w64-headers/crt/math.h
@@ -698,6 +698,43 @@ __mingw_choose_expr (                                      
   \
 #endif
   extern long double __cdecl tanhl(long double);
 
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+/* 7.12.4.8 */
+  double __cdecl acospi(double _X);
+  float __cdecl acospif(float _X);
+  long double __cdecl acospil(long double _X);
+
+/* 7.12.4.9 */
+  double __cdecl asinpi(double _X);
+  float __cdecl asinpif(float _X);
+  long double __cdecl asinpil(long double _X);
+
+/* 7.12.4.10 */
+  double __cdecl atanpi(double _X);
+  float __cdecl atanpif(float _X);
+  long double __cdecl atanpil(long double _X);
+
+/* 7.12.4.11 */
+  double __cdecl atan2pi(double _X, double _Y);
+  float __cdecl atan2pif(float _X, float _Y);
+  long double __cdecl atan2pil(long double _X, long double _X);
+
+/* 7.12.4.12 */
+  double __cdecl cospi(double _X);
+  float __cdecl cospif(float _X);
+  long double __cdecl cospil(long double _X);
+
+/* 7.12.4.13 */
+  double __cdecl sinpi(double _X);
+  float __cdecl sinpif(float _X);
+  long double __cdecl sinpil(long double _X);
+
+/* 7.12.4.14 */
+  double __cdecl tanpi(double _X);
+  float __cdecl tanpif(float _X);
+  long double __cdecl tanpil(long double _X);
+#endif
+
 /* Inverse hyperbolic trig functions  */ 
 /* 7.12.5.1 */
   extern double __cdecl acosh (double);
-- 
2.51.0.windows.2

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to