Am 09.01.2026 um 04:00 schrieb LIU Hao:
This patch duplicates the definition of `M_PI` in every file. I think for `M_PI` you can just `#define _USE_MATH_DEFINES` before including <math.h>. If it doesn't work, you can add it to `AM_CPPFLAGS`.
Thanks for the suggestion. I didn't like the duplication of the definition either. Your suggestion is much more elegant.
The attached updated patch makes sure that `_USE_MATH_DEFINES` is defined before including `math.h`.
Please, let me know if other changes are necessary. Markus
From e22b5f0e6024b1e0505a63b578f5e02119e0db7d 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 [-2, 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 | 10 ++++++++- mingw-w64-crt/math/acospi.c | 16 +++++++++++++++ mingw-w64-crt/math/acospif.c | 16 +++++++++++++++ mingw-w64-crt/math/acospil.c | 16 +++++++++++++++ mingw-w64-crt/math/asinpi.c | 16 +++++++++++++++ mingw-w64-crt/math/asinpif.c | 16 +++++++++++++++ mingw-w64-crt/math/asinpil.c | 16 +++++++++++++++ mingw-w64-crt/math/atan2pi.c | 16 +++++++++++++++ mingw-w64-crt/math/atan2pif.c | 16 +++++++++++++++ mingw-w64-crt/math/atan2pil.c | 16 +++++++++++++++ mingw-w64-crt/math/atanpi.c | 16 +++++++++++++++ mingw-w64-crt/math/atanpif.c | 16 +++++++++++++++ mingw-w64-crt/math/atanpil.c | 16 +++++++++++++++ mingw-w64-crt/math/cospi.c | 17 ++++++++++++++++ mingw-w64-crt/math/cospif.c | 17 ++++++++++++++++ mingw-w64-crt/math/cospil.c | 17 ++++++++++++++++ mingw-w64-crt/math/sinpi.c | 17 ++++++++++++++++ mingw-w64-crt/math/sinpif.c | 17 ++++++++++++++++ mingw-w64-crt/math/sinpil.c | 17 ++++++++++++++++ mingw-w64-crt/math/tanpi.c | 17 ++++++++++++++++ mingw-w64-crt/math/tanpif.c | 17 ++++++++++++++++ mingw-w64-crt/math/tanpil.c | 17 ++++++++++++++++ mingw-w64-headers/crt/math.h | 38 +++++++++++++++++++++++++++++++++++ 23 files changed, 392 insertions(+), 1 deletion(-) create mode 100644 mingw-w64-crt/math/acospi.c create mode 100644 mingw-w64-crt/math/acospif.c create mode 100644 mingw-w64-crt/math/acospil.c create mode 100644 mingw-w64-crt/math/asinpi.c create mode 100644 mingw-w64-crt/math/asinpif.c create mode 100644 mingw-w64-crt/math/asinpil.c create mode 100644 mingw-w64-crt/math/atan2pi.c create mode 100644 mingw-w64-crt/math/atan2pif.c create mode 100644 mingw-w64-crt/math/atan2pil.c create mode 100644 mingw-w64-crt/math/atanpi.c create mode 100644 mingw-w64-crt/math/atanpif.c create mode 100644 mingw-w64-crt/math/atanpil.c create mode 100644 mingw-w64-crt/math/cospi.c create mode 100644 mingw-w64-crt/math/cospif.c create mode 100644 mingw-w64-crt/math/cospil.c create mode 100644 mingw-w64-crt/math/sinpi.c create mode 100644 mingw-w64-crt/math/sinpif.c create mode 100644 mingw-w64-crt/math/sinpil.c create mode 100644 mingw-w64-crt/math/tanpi.c create mode 100644 mingw-w64-crt/math/tanpif.c create mode 100644 mingw-w64-crt/math/tanpil.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index ff032f953..c8bce98e4 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -1214,7 +1214,12 @@ src_libmingwex=\ gdtoa/misc.c gdtoa/qnan.c gdtoa/smisc.c gdtoa/strtodg.c gdtoa/strtodnrp.c gdtoa/strtof.c \ gdtoa/strtopx.c gdtoa/sum.c gdtoa/ulp.c \ \ + math/acospi.c math/acospif.c math/acospil.c \ + math/asinpi.c math/asinpif.c math/asinpil.c \ + math/atan2pi.c math/atan2pif.c math/atan2pil.c \ + math/atanpi.c math/atanpif.c math/atanpil.c \ math/coshl.c \ + math/cospi.c math/cospif.c math/cospil.c \ math/fabsl.c math/fp_consts.c math/fp_constsf.c \ math/fp_constsl.c math/fpclassify.c math/fpclassifyf.c math/fpclassifyl.c math/frexpf.c math/frexpl.c \ math/hypotf.c math/hypotl.c math/isnan.c math/isnanf.c math/isnanl.c \ @@ -1223,7 +1228,10 @@ src_libmingwex=\ math/powi.c math/powif.c math/powil.c \ math/signbit.c math/signbitf.c math/signbitl.c \ math/signgam.c \ - math/sinhl.c math/sqrtl.c math/tanhl.c \ + math/sinhl.c \ + math/sinpi.c math/sinpif.c math/sinpil.c \ + math/sqrtl.c math/tanhl.c \ + math/tanpi.c math/tanpif.c math/tanpil.c \ math/powi.def.h math/sqrt.def.h \ math/cephes_mconf.h math/fp_consts.h \ \ diff --git a/mingw-w64-crt/math/acospi.c b/mingw-w64-crt/math/acospi.c new file mode 100644 index 000000000..0dbaa62b9 --- /dev/null +++ b/mingw-w64-crt/math/acospi.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl acospi(double x) +{ + return acos(x)/M_PI; +} diff --git a/mingw-w64-crt/math/acospif.c b/mingw-w64-crt/math/acospif.c new file mode 100644 index 000000000..facd8caab --- /dev/null +++ b/mingw-w64-crt/math/acospif.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl acospif(float x) +{ + return acosf(x)/M_PI; +} diff --git a/mingw-w64-crt/math/acospil.c b/mingw-w64-crt/math/acospil.c new file mode 100644 index 000000000..485e4f8a5 --- /dev/null +++ b/mingw-w64-crt/math/acospil.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +long double __cdecl acospil(long double x) +{ + return acosl(x)/M_PI; +} diff --git a/mingw-w64-crt/math/asinpi.c b/mingw-w64-crt/math/asinpi.c new file mode 100644 index 000000000..479f0bbcd --- /dev/null +++ b/mingw-w64-crt/math/asinpi.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl asinpi(double x) +{ + return asin(x)/M_PI; +} diff --git a/mingw-w64-crt/math/asinpif.c b/mingw-w64-crt/math/asinpif.c new file mode 100644 index 000000000..62968f2ba --- /dev/null +++ b/mingw-w64-crt/math/asinpif.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl asinpif(float x) +{ + return asinf(x)/M_PI; +} diff --git a/mingw-w64-crt/math/asinpil.c b/mingw-w64-crt/math/asinpil.c new file mode 100644 index 000000000..9a219b075 --- /dev/null +++ b/mingw-w64-crt/math/asinpil.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +long double __cdecl asinpil(long double x) +{ + return asinl(x)/M_PI; +} diff --git a/mingw-w64-crt/math/atan2pi.c b/mingw-w64-crt/math/atan2pi.c new file mode 100644 index 000000000..4c344d072 --- /dev/null +++ b/mingw-w64-crt/math/atan2pi.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl atan2pi(double x, double y) +{ + return atan2(x, y)/M_PI; +} diff --git a/mingw-w64-crt/math/atan2pif.c b/mingw-w64-crt/math/atan2pif.c new file mode 100644 index 000000000..5cfd654c5 --- /dev/null +++ b/mingw-w64-crt/math/atan2pif.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl atan2pif(float x, float y) +{ + return atan2f(x, y)/M_PI; +} diff --git a/mingw-w64-crt/math/atan2pil.c b/mingw-w64-crt/math/atan2pil.c new file mode 100644 index 000000000..8fb74b2a0 --- /dev/null +++ b/mingw-w64-crt/math/atan2pil.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +long double __cdecl atan2pil(long double x, long double y) +{ + return atan2l(x, y)/M_PI; +} diff --git a/mingw-w64-crt/math/atanpi.c b/mingw-w64-crt/math/atanpi.c new file mode 100644 index 000000000..ebca417ea --- /dev/null +++ b/mingw-w64-crt/math/atanpi.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl atanpi(double x) +{ + return atan(x)/M_PI; +} diff --git a/mingw-w64-crt/math/atanpif.c b/mingw-w64-crt/math/atanpif.c new file mode 100644 index 000000000..47e414a71 --- /dev/null +++ b/mingw-w64-crt/math/atanpif.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl atanpif(float x) +{ + return atanf(x)/M_PI; +} diff --git a/mingw-w64-crt/math/atanpil.c b/mingw-w64-crt/math/atanpil.c new file mode 100644 index 000000000..06aae1732 --- /dev/null +++ b/mingw-w64-crt/math/atanpil.c @@ -0,0 +1,16 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +long double __cdecl atanpil(long double x) +{ + return atanl(x)/M_PI; +} diff --git a/mingw-w64-crt/math/cospi.c b/mingw-w64-crt/math/cospi.c new file mode 100644 index 000000000..ea3236242 --- /dev/null +++ b/mingw-w64-crt/math/cospi.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl cospi(double x) +{ + x = fmod(x, 2.0); + return cos(x*M_PI); +} diff --git a/mingw-w64-crt/math/cospif.c b/mingw-w64-crt/math/cospif.c new file mode 100644 index 000000000..d7301a42b --- /dev/null +++ b/mingw-w64-crt/math/cospif.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl cospif(float x) +{ + x = fmodf(x, 2.0F); + return cosf(x*M_PI); +} diff --git a/mingw-w64-crt/math/cospil.c b/mingw-w64-crt/math/cospil.c new file mode 100644 index 000000000..bd10c5f73 --- /dev/null +++ b/mingw-w64-crt/math/cospil.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +long double __cdecl cospil(long double x) +{ + x = fmodl(x, 2.0L); + return cosl(x*M_PI); +} diff --git a/mingw-w64-crt/math/sinpi.c b/mingw-w64-crt/math/sinpi.c new file mode 100644 index 000000000..c932c20f2 --- /dev/null +++ b/mingw-w64-crt/math/sinpi.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl sinpi(double x) +{ + x = remainder(x, 2.0); + return sin(x*M_PI); +} diff --git a/mingw-w64-crt/math/sinpif.c b/mingw-w64-crt/math/sinpif.c new file mode 100644 index 000000000..9d84ff32e --- /dev/null +++ b/mingw-w64-crt/math/sinpif.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl sinpif(float x) +{ + x = remainderf(x, 2.0F); + return sinf(x*M_PI); +} diff --git a/mingw-w64-crt/math/sinpil.c b/mingw-w64-crt/math/sinpil.c new file mode 100644 index 000000000..c8e12c35b --- /dev/null +++ b/mingw-w64-crt/math/sinpil.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +long double __cdecl sinpil(long double x) +{ + x = remainderl(x, 2.0L); + return sinl(x*M_PI); +} diff --git a/mingw-w64-crt/math/tanpi.c b/mingw-w64-crt/math/tanpi.c new file mode 100644 index 000000000..a574fea96 --- /dev/null +++ b/mingw-w64-crt/math/tanpi.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +double __cdecl tanpi(double x) +{ + x = remainder(x, 2.0); + return tan(x*M_PI); +} diff --git a/mingw-w64-crt/math/tanpif.c b/mingw-w64-crt/math/tanpif.c new file mode 100644 index 000000000..24bd90b5f --- /dev/null +++ b/mingw-w64-crt/math/tanpif.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +float __cdecl tanpif(float x) +{ + x = remainderf(x, 2.0F); + return tanf(x*M_PI); +} diff --git a/mingw-w64-crt/math/tanpil.c b/mingw-w64-crt/math/tanpil.c new file mode 100644 index 000000000..8c5204f31 --- /dev/null +++ b/mingw-w64-crt/math/tanpil.c @@ -0,0 +1,17 @@ +/** + * 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. + */ + +#if !defined(_USE_MATH_DEFINES) +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +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..a597e57a5 100644 --- a/mingw-w64-headers/crt/math.h +++ b/mingw-w64-headers/crt/math.h @@ -698,6 +698,44 @@ __mingw_choose_expr ( \ #endif extern long double __cdecl tanhl(long double); +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) \ + || defined(_CRTBLD) +/* 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 _Y); + +/* 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
