Skip to content

Commit 2e57bc8

Browse files
committed
Added sin(pi*x) cos(pi*x) and tan(pi*x)
1 parent 5833aa0 commit 2e57bc8

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

src/libc/include/__math_def.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ double cos(double);
110110
float cosf(float);
111111
long double cosl(long double);
112112

113+
double cospi(double);
114+
float cospif(float);
115+
long double cospil(long double);
116+
113117
double cosh(double);
114118
float coshf(float);
115119
long double coshl(long double);
@@ -289,6 +293,10 @@ double sin(double);
289293
float sinf(float);
290294
long double sinl(long double);
291295

296+
double sinpi(double);
297+
float sinpif(float);
298+
long double sinpil(long double);
299+
292300
double sinh(double);
293301
float sinhf(float);
294302
long double sinhl(long double);
@@ -301,6 +309,10 @@ double tan(double);
301309
float tanf(float);
302310
long double tanl(long double);
303311

312+
double tanpi(double);
313+
float tanpif(float);
314+
long double tanpil(long double);
315+
304316
double tanh(double);
305317
float tanhf(float);
306318
long double tanhl(long double);

src/libc/include/tgmath.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
float: cosf \
7272
)(x)
7373

74+
#define cospi(x) _Generic(__tgmath_promote(x), \
75+
long double: cospil, \
76+
default: cospi, \
77+
float: cospif \
78+
)(x)
79+
7480
#define cosh(x) _Generic(__tgmath_promote(x), \
7581
long double: coshl, \
7682
default: cosh, \
@@ -227,6 +233,12 @@
227233
float: sinf \
228234
)(x)
229235

236+
#define sinpi(x) _Generic(__tgmath_promote(x), \
237+
long double: sinpil, \
238+
default: sinpi, \
239+
float: sinpif \
240+
)(x)
241+
230242
#define sinh(x) _Generic(__tgmath_promote(x), \
231243
long double: sinhl, \
232244
default: sinh, \
@@ -245,6 +257,12 @@
245257
float: tanf \
246258
)(x)
247259

260+
#define tanpi(x) _Generic(__tgmath_promote(x), \
261+
long double: tanpil, \
262+
default: tanpi, \
263+
float: tanpif \
264+
)(x)
265+
248266
#define tanh(x) _Generic(__tgmath_promote(x), \
249267
long double: tanhl, \
250268
default: tanh, \

src/libc/trigpif.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <math.h>
2+
#include "__float32_constants.h"
3+
4+
static float reduce_f32(float x) {
5+
// x is (-2.0, +2.0)
6+
return (x - 2.0f * truncf(x * 0.5f)) * F32_PI;
7+
}
8+
9+
float sinpif(float x) {
10+
return sinf(reduce_f32(x));
11+
}
12+
13+
float cospif(float x) {
14+
return cosf(reduce_f32(x));
15+
}
16+
17+
float tanpif(float x) {
18+
return tanf(reduce_f32(x));
19+
}
20+
21+
double sinpi(double) __attribute__((alias("sinpif")));
22+
double cospi(double) __attribute__((alias("cospif")));
23+
double tanpi(double) __attribute__((alias("tanpif")));

src/libc/trigpil.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <math.h>
2+
#include "__float64_constants.h"
3+
4+
static long double reduce_f64(long double x) {
5+
// x is (-2.0, +2.0)
6+
return (x - 2.0L * truncl(x * 0.5L)) * F64_PI;
7+
}
8+
9+
long double sinpil(long double x) {
10+
return sinl(reduce_f64(x));
11+
}
12+
13+
long double cospil(long double x) {
14+
return cosl(reduce_f64(x));
15+
}
16+
17+
long double tanpil(long double x) {
18+
return tanl(reduce_f64(x));
19+
}

src/libcxx/include/cmath

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ template<typename _Tp> inline constexpr
209209
__cmath_enable_if_t<__cmath_is_integral_v<_Tp>, double>
210210
cos(_Tp __x) { return cos(__x); }
211211

212+
using ::cospi;
213+
using ::cospif;
214+
using ::cospil;
215+
inline float cospi(float __x) { return cospif(__x); }
216+
inline long double cospi(long double __x) { return cospil(__x); }
217+
template<typename _Tp> inline
218+
__cmath_enable_if_t<__cmath_is_integral_v<_Tp>, double>
219+
cospi(_Tp __x) { return cospi(__x); }
220+
212221
using ::cosh;
213222
using ::coshf;
214223
using ::coshl;
@@ -594,6 +603,15 @@ template<typename _Tp> inline constexpr
594603
__cmath_enable_if_t<__cmath_is_integral_v<_Tp>, double>
595604
sin(_Tp __x) { return sin(__x); }
596605

606+
using ::sinpi;
607+
using ::sinpif;
608+
using ::sinpil;
609+
inline float sinpi(float __x) { return sinpif(__x); }
610+
inline long double sinpi(long double __x) { return sinpil(__x); }
611+
template<typename _Tp> inline
612+
__cmath_enable_if_t<__cmath_is_integral_v<_Tp>, double>
613+
sinpi(_Tp __x) { return sinpi(__x); }
614+
597615
using ::sinh;
598616
using ::sinhf;
599617
using ::sinhl;
@@ -621,6 +639,15 @@ template<typename _Tp> inline constexpr
621639
__cmath_enable_if_t<__cmath_is_integral_v<_Tp>, double>
622640
tan(_Tp __x) { return tan(__x); }
623641

642+
using ::tanpi;
643+
using ::tanpif;
644+
using ::tanpil;
645+
inline float tanpi(float __x) { return tanpif(__x); }
646+
inline long double tanpi(long double __x) { return tanpil(__x); }
647+
template<typename _Tp> inline
648+
__cmath_enable_if_t<__cmath_is_integral_v<_Tp>, double>
649+
tanpi(_Tp __x) { return tanpi(__x); }
650+
624651
using ::tanh;
625652
using ::tanhf;
626653
using ::tanhl;

0 commit comments

Comments
 (0)