mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
libc: replace musl's trigonometric functions with compiler_rt's
- sin - sinf - cos - cosf - sincos - sincosf - tan - tanf
This commit is contained in:
parent
0cbff2ff7f
commit
21d9e03758
10 changed files with 0 additions and 645 deletions
77
lib/libc/musl/src/math/cos.c
vendored
77
lib/libc/musl/src/math/cos.c
vendored
|
|
@ -1,77 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
/* cos(x)
|
|
||||||
* Return cosine function of x.
|
|
||||||
*
|
|
||||||
* kernel function:
|
|
||||||
* __sin ... sine function on [-pi/4,pi/4]
|
|
||||||
* __cos ... cosine function on [-pi/4,pi/4]
|
|
||||||
* __rem_pio2 ... argument reduction routine
|
|
||||||
*
|
|
||||||
* Method.
|
|
||||||
* Let S,C and T denote the sin, cos and tan respectively on
|
|
||||||
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
|
|
||||||
* in [-pi/4 , +pi/4], and let n = k mod 4.
|
|
||||||
* We have
|
|
||||||
*
|
|
||||||
* n sin(x) cos(x) tan(x)
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
* 0 S C T
|
|
||||||
* 1 C -S -1/T
|
|
||||||
* 2 -S -C T
|
|
||||||
* 3 -C S -1/T
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Special cases:
|
|
||||||
* Let trig be any of sin, cos, or tan.
|
|
||||||
* trig(+-INF) is NaN, with signals;
|
|
||||||
* trig(NaN) is that NaN;
|
|
||||||
*
|
|
||||||
* Accuracy:
|
|
||||||
* TRIG(x) returns trig(x) nearly rounded
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
double cos(double x)
|
|
||||||
{
|
|
||||||
double y[2];
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n;
|
|
||||||
|
|
||||||
GET_HIGH_WORD(ix, x);
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
/* |x| ~< pi/4 */
|
|
||||||
if (ix <= 0x3fe921fb) {
|
|
||||||
if (ix < 0x3e46a09e) { /* |x| < 2**-27 * sqrt(2) */
|
|
||||||
/* raise inexact if x!=0 */
|
|
||||||
FORCE_EVAL(x + 0x1p120f);
|
|
||||||
return 1.0;
|
|
||||||
}
|
|
||||||
return __cos(x, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cos(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7ff00000)
|
|
||||||
return x-x;
|
|
||||||
|
|
||||||
/* argument reduction */
|
|
||||||
n = __rem_pio2(x, y);
|
|
||||||
switch (n&3) {
|
|
||||||
case 0: return __cos(y[0], y[1]);
|
|
||||||
case 1: return -__sin(y[0], y[1], 1);
|
|
||||||
case 2: return -__cos(y[0], y[1]);
|
|
||||||
default:
|
|
||||||
return __sin(y[0], y[1], 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
78
lib/libc/musl/src/math/cosf.c
vendored
78
lib/libc/musl/src/math/cosf.c
vendored
|
|
@ -1,78 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_cosf.c */
|
|
||||||
/*
|
|
||||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
||||||
* Optimized by Bruce D. Evans.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
/* Small multiples of pi/2 rounded to double precision. */
|
|
||||||
static const double
|
|
||||||
c1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */
|
|
||||||
c2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */
|
|
||||||
c3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */
|
|
||||||
c4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */
|
|
||||||
|
|
||||||
float cosf(float x)
|
|
||||||
{
|
|
||||||
double y;
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n, sign;
|
|
||||||
|
|
||||||
GET_FLOAT_WORD(ix, x);
|
|
||||||
sign = ix >> 31;
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
|
|
||||||
if (ix < 0x39800000) { /* |x| < 2**-12 */
|
|
||||||
/* raise inexact if x != 0 */
|
|
||||||
FORCE_EVAL(x + 0x1p120f);
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
return __cosdf(x);
|
|
||||||
}
|
|
||||||
if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
|
|
||||||
if (ix > 0x4016cbe3) /* |x| ~> 3*pi/4 */
|
|
||||||
return -__cosdf(sign ? x+c2pio2 : x-c2pio2);
|
|
||||||
else {
|
|
||||||
if (sign)
|
|
||||||
return __sindf(x + c1pio2);
|
|
||||||
else
|
|
||||||
return __sindf(c1pio2 - x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
|
|
||||||
if (ix > 0x40afeddf) /* |x| ~> 7*pi/4 */
|
|
||||||
return __cosdf(sign ? x+c4pio2 : x-c4pio2);
|
|
||||||
else {
|
|
||||||
if (sign)
|
|
||||||
return __sindf(-x - c3pio2);
|
|
||||||
else
|
|
||||||
return __sindf(x - c3pio2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cos(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7f800000)
|
|
||||||
return x-x;
|
|
||||||
|
|
||||||
/* general argument reduction needed */
|
|
||||||
n = __rem_pio2f(x,&y);
|
|
||||||
switch (n&3) {
|
|
||||||
case 0: return __cosdf(y);
|
|
||||||
case 1: return __sindf(-y);
|
|
||||||
case 2: return -__cosdf(y);
|
|
||||||
default:
|
|
||||||
return __sindf(y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
78
lib/libc/musl/src/math/sin.c
vendored
78
lib/libc/musl/src/math/sin.c
vendored
|
|
@ -1,78 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
/* sin(x)
|
|
||||||
* Return sine function of x.
|
|
||||||
*
|
|
||||||
* kernel function:
|
|
||||||
* __sin ... sine function on [-pi/4,pi/4]
|
|
||||||
* __cos ... cose function on [-pi/4,pi/4]
|
|
||||||
* __rem_pio2 ... argument reduction routine
|
|
||||||
*
|
|
||||||
* Method.
|
|
||||||
* Let S,C and T denote the sin, cos and tan respectively on
|
|
||||||
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
|
|
||||||
* in [-pi/4 , +pi/4], and let n = k mod 4.
|
|
||||||
* We have
|
|
||||||
*
|
|
||||||
* n sin(x) cos(x) tan(x)
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
* 0 S C T
|
|
||||||
* 1 C -S -1/T
|
|
||||||
* 2 -S -C T
|
|
||||||
* 3 -C S -1/T
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Special cases:
|
|
||||||
* Let trig be any of sin, cos, or tan.
|
|
||||||
* trig(+-INF) is NaN, with signals;
|
|
||||||
* trig(NaN) is that NaN;
|
|
||||||
*
|
|
||||||
* Accuracy:
|
|
||||||
* TRIG(x) returns trig(x) nearly rounded
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
double sin(double x)
|
|
||||||
{
|
|
||||||
double y[2];
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n;
|
|
||||||
|
|
||||||
/* High word of x. */
|
|
||||||
GET_HIGH_WORD(ix, x);
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
/* |x| ~< pi/4 */
|
|
||||||
if (ix <= 0x3fe921fb) {
|
|
||||||
if (ix < 0x3e500000) { /* |x| < 2**-26 */
|
|
||||||
/* raise inexact if x != 0 and underflow if subnormal*/
|
|
||||||
FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
return __sin(x, 0.0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sin(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7ff00000)
|
|
||||||
return x - x;
|
|
||||||
|
|
||||||
/* argument reduction needed */
|
|
||||||
n = __rem_pio2(x, y);
|
|
||||||
switch (n&3) {
|
|
||||||
case 0: return __sin(y[0], y[1], 1);
|
|
||||||
case 1: return __cos(y[0], y[1]);
|
|
||||||
case 2: return -__sin(y[0], y[1], 1);
|
|
||||||
default:
|
|
||||||
return -__cos(y[0], y[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
69
lib/libc/musl/src/math/sincos.c
vendored
69
lib/libc/musl/src/math/sincos.c
vendored
|
|
@ -1,69 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
void sincos(double x, double *sin, double *cos)
|
|
||||||
{
|
|
||||||
double y[2], s, c;
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n;
|
|
||||||
|
|
||||||
GET_HIGH_WORD(ix, x);
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
/* |x| ~< pi/4 */
|
|
||||||
if (ix <= 0x3fe921fb) {
|
|
||||||
/* if |x| < 2**-27 * sqrt(2) */
|
|
||||||
if (ix < 0x3e46a09e) {
|
|
||||||
/* raise inexact if x!=0 and underflow if subnormal */
|
|
||||||
FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
|
|
||||||
*sin = x;
|
|
||||||
*cos = 1.0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*sin = __sin(x, 0.0, 0);
|
|
||||||
*cos = __cos(x, 0.0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sincos(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7ff00000) {
|
|
||||||
*sin = *cos = x - x;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* argument reduction needed */
|
|
||||||
n = __rem_pio2(x, y);
|
|
||||||
s = __sin(y[0], y[1], 1);
|
|
||||||
c = __cos(y[0], y[1]);
|
|
||||||
switch (n&3) {
|
|
||||||
case 0:
|
|
||||||
*sin = s;
|
|
||||||
*cos = c;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
*sin = c;
|
|
||||||
*cos = -s;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
*sin = -s;
|
|
||||||
*cos = -c;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
default:
|
|
||||||
*sin = -c;
|
|
||||||
*cos = s;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
117
lib/libc/musl/src/math/sincosf.c
vendored
117
lib/libc/musl/src/math/sincosf.c
vendored
|
|
@ -1,117 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */
|
|
||||||
/*
|
|
||||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
||||||
* Optimized by Bruce D. Evans.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
/* Small multiples of pi/2 rounded to double precision. */
|
|
||||||
static const double
|
|
||||||
s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */
|
|
||||||
s2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */
|
|
||||||
s3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */
|
|
||||||
s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */
|
|
||||||
|
|
||||||
void sincosf(float x, float *sin, float *cos)
|
|
||||||
{
|
|
||||||
double y;
|
|
||||||
float_t s, c;
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n, sign;
|
|
||||||
|
|
||||||
GET_FLOAT_WORD(ix, x);
|
|
||||||
sign = ix >> 31;
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
/* |x| ~<= pi/4 */
|
|
||||||
if (ix <= 0x3f490fda) {
|
|
||||||
/* |x| < 2**-12 */
|
|
||||||
if (ix < 0x39800000) {
|
|
||||||
/* raise inexact if x!=0 and underflow if subnormal */
|
|
||||||
FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
|
|
||||||
*sin = x;
|
|
||||||
*cos = 1.0f;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*sin = __sindf(x);
|
|
||||||
*cos = __cosdf(x);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* |x| ~<= 5*pi/4 */
|
|
||||||
if (ix <= 0x407b53d1) {
|
|
||||||
if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */
|
|
||||||
if (sign) {
|
|
||||||
*sin = -__cosdf(x + s1pio2);
|
|
||||||
*cos = __sindf(x + s1pio2);
|
|
||||||
} else {
|
|
||||||
*sin = __cosdf(s1pio2 - x);
|
|
||||||
*cos = __sindf(s1pio2 - x);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */
|
|
||||||
*sin = -__sindf(sign ? x + s2pio2 : x - s2pio2);
|
|
||||||
*cos = -__cosdf(sign ? x + s2pio2 : x - s2pio2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* |x| ~<= 9*pi/4 */
|
|
||||||
if (ix <= 0x40e231d5) {
|
|
||||||
if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */
|
|
||||||
if (sign) {
|
|
||||||
*sin = __cosdf(x + s3pio2);
|
|
||||||
*cos = -__sindf(x + s3pio2);
|
|
||||||
} else {
|
|
||||||
*sin = -__cosdf(x - s3pio2);
|
|
||||||
*cos = __sindf(x - s3pio2);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*sin = __sindf(sign ? x + s4pio2 : x - s4pio2);
|
|
||||||
*cos = __cosdf(sign ? x + s4pio2 : x - s4pio2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sin(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7f800000) {
|
|
||||||
*sin = *cos = x - x;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* general argument reduction needed */
|
|
||||||
n = __rem_pio2f(x, &y);
|
|
||||||
s = __sindf(y);
|
|
||||||
c = __cosdf(y);
|
|
||||||
switch (n&3) {
|
|
||||||
case 0:
|
|
||||||
*sin = s;
|
|
||||||
*cos = c;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
*sin = c;
|
|
||||||
*cos = -s;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
*sin = -s;
|
|
||||||
*cos = -c;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
default:
|
|
||||||
*sin = -c;
|
|
||||||
*cos = s;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
76
lib/libc/musl/src/math/sinf.c
vendored
76
lib/libc/musl/src/math/sinf.c
vendored
|
|
@ -1,76 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */
|
|
||||||
/*
|
|
||||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
||||||
* Optimized by Bruce D. Evans.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
/* Small multiples of pi/2 rounded to double precision. */
|
|
||||||
static const double
|
|
||||||
s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */
|
|
||||||
s2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */
|
|
||||||
s3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */
|
|
||||||
s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */
|
|
||||||
|
|
||||||
float sinf(float x)
|
|
||||||
{
|
|
||||||
double y;
|
|
||||||
uint32_t ix;
|
|
||||||
int n, sign;
|
|
||||||
|
|
||||||
GET_FLOAT_WORD(ix, x);
|
|
||||||
sign = ix >> 31;
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
|
|
||||||
if (ix < 0x39800000) { /* |x| < 2**-12 */
|
|
||||||
/* raise inexact if x!=0 and underflow if subnormal */
|
|
||||||
FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
return __sindf(x);
|
|
||||||
}
|
|
||||||
if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
|
|
||||||
if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */
|
|
||||||
if (sign)
|
|
||||||
return -__cosdf(x + s1pio2);
|
|
||||||
else
|
|
||||||
return __cosdf(x - s1pio2);
|
|
||||||
}
|
|
||||||
return __sindf(sign ? -(x + s2pio2) : -(x - s2pio2));
|
|
||||||
}
|
|
||||||
if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
|
|
||||||
if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */
|
|
||||||
if (sign)
|
|
||||||
return __cosdf(x + s3pio2);
|
|
||||||
else
|
|
||||||
return -__cosdf(x - s3pio2);
|
|
||||||
}
|
|
||||||
return __sindf(sign ? x + s4pio2 : x - s4pio2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sin(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7f800000)
|
|
||||||
return x - x;
|
|
||||||
|
|
||||||
/* general argument reduction needed */
|
|
||||||
n = __rem_pio2f(x, &y);
|
|
||||||
switch (n&3) {
|
|
||||||
case 0: return __sindf(y);
|
|
||||||
case 1: return __cosdf(y);
|
|
||||||
case 2: return __sindf(-y);
|
|
||||||
default:
|
|
||||||
return -__cosdf(y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
70
lib/libc/musl/src/math/tan.c
vendored
70
lib/libc/musl/src/math/tan.c
vendored
|
|
@ -1,70 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
/* tan(x)
|
|
||||||
* Return tangent function of x.
|
|
||||||
*
|
|
||||||
* kernel function:
|
|
||||||
* __tan ... tangent function on [-pi/4,pi/4]
|
|
||||||
* __rem_pio2 ... argument reduction routine
|
|
||||||
*
|
|
||||||
* Method.
|
|
||||||
* Let S,C and T denote the sin, cos and tan respectively on
|
|
||||||
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
|
|
||||||
* in [-pi/4 , +pi/4], and let n = k mod 4.
|
|
||||||
* We have
|
|
||||||
*
|
|
||||||
* n sin(x) cos(x) tan(x)
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
* 0 S C T
|
|
||||||
* 1 C -S -1/T
|
|
||||||
* 2 -S -C T
|
|
||||||
* 3 -C S -1/T
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Special cases:
|
|
||||||
* Let trig be any of sin, cos, or tan.
|
|
||||||
* trig(+-INF) is NaN, with signals;
|
|
||||||
* trig(NaN) is that NaN;
|
|
||||||
*
|
|
||||||
* Accuracy:
|
|
||||||
* TRIG(x) returns trig(x) nearly rounded
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
double tan(double x)
|
|
||||||
{
|
|
||||||
double y[2];
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n;
|
|
||||||
|
|
||||||
GET_HIGH_WORD(ix, x);
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
/* |x| ~< pi/4 */
|
|
||||||
if (ix <= 0x3fe921fb) {
|
|
||||||
if (ix < 0x3e400000) { /* |x| < 2**-27 */
|
|
||||||
/* raise inexact if x!=0 and underflow if subnormal */
|
|
||||||
FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
return __tan(x, 0.0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* tan(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7ff00000)
|
|
||||||
return x - x;
|
|
||||||
|
|
||||||
/* argument reduction */
|
|
||||||
n = __rem_pio2(x, y);
|
|
||||||
return __tan(y[0], y[1], n&1);
|
|
||||||
}
|
|
||||||
64
lib/libc/musl/src/math/tanf.c
vendored
64
lib/libc/musl/src/math/tanf.c
vendored
|
|
@ -1,64 +0,0 @@
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_tanf.c */
|
|
||||||
/*
|
|
||||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
||||||
* Optimized by Bruce D. Evans.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* ====================================================
|
|
||||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
||||||
* Permission to use, copy, modify, and distribute this
|
|
||||||
* software is freely granted, provided that this notice
|
|
||||||
* is preserved.
|
|
||||||
* ====================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libm.h"
|
|
||||||
|
|
||||||
/* Small multiples of pi/2 rounded to double precision. */
|
|
||||||
static const double
|
|
||||||
t1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */
|
|
||||||
t2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */
|
|
||||||
t3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */
|
|
||||||
t4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */
|
|
||||||
|
|
||||||
float tanf(float x)
|
|
||||||
{
|
|
||||||
double y;
|
|
||||||
uint32_t ix;
|
|
||||||
unsigned n, sign;
|
|
||||||
|
|
||||||
GET_FLOAT_WORD(ix, x);
|
|
||||||
sign = ix >> 31;
|
|
||||||
ix &= 0x7fffffff;
|
|
||||||
|
|
||||||
if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
|
|
||||||
if (ix < 0x39800000) { /* |x| < 2**-12 */
|
|
||||||
/* raise inexact if x!=0 and underflow if subnormal */
|
|
||||||
FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
return __tandf(x, 0);
|
|
||||||
}
|
|
||||||
if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
|
|
||||||
if (ix <= 0x4016cbe3) /* |x| ~<= 3pi/4 */
|
|
||||||
return __tandf((sign ? x+t1pio2 : x-t1pio2), 1);
|
|
||||||
else
|
|
||||||
return __tandf((sign ? x+t2pio2 : x-t2pio2), 0);
|
|
||||||
}
|
|
||||||
if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
|
|
||||||
if (ix <= 0x40afeddf) /* |x| ~<= 7*pi/4 */
|
|
||||||
return __tandf((sign ? x+t3pio2 : x-t3pio2), 1);
|
|
||||||
else
|
|
||||||
return __tandf((sign ? x+t4pio2 : x-t4pio2), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* tan(Inf or NaN) is NaN */
|
|
||||||
if (ix >= 0x7f800000)
|
|
||||||
return x - x;
|
|
||||||
|
|
||||||
/* argument reduction */
|
|
||||||
n = __rem_pio2f(x, &y);
|
|
||||||
return __tandf(y, n&1);
|
|
||||||
}
|
|
||||||
|
|
@ -886,9 +886,7 @@ const src_files = [_][]const u8{
|
||||||
"musl/src/math/copysignf.c",
|
"musl/src/math/copysignf.c",
|
||||||
"musl/src/math/copysignl.c",
|
"musl/src/math/copysignl.c",
|
||||||
"musl/src/math/__cos.c",
|
"musl/src/math/__cos.c",
|
||||||
"musl/src/math/cos.c",
|
|
||||||
"musl/src/math/__cosdf.c",
|
"musl/src/math/__cosdf.c",
|
||||||
"musl/src/math/cosf.c",
|
|
||||||
"musl/src/math/cosh.c",
|
"musl/src/math/cosh.c",
|
||||||
"musl/src/math/coshf.c",
|
"musl/src/math/coshf.c",
|
||||||
"musl/src/math/coshl.c",
|
"musl/src/math/coshl.c",
|
||||||
|
|
@ -1194,12 +1192,8 @@ const src_files = [_][]const u8{
|
||||||
"musl/src/math/significand.c",
|
"musl/src/math/significand.c",
|
||||||
"musl/src/math/significandf.c",
|
"musl/src/math/significandf.c",
|
||||||
"musl/src/math/__sin.c",
|
"musl/src/math/__sin.c",
|
||||||
"musl/src/math/sin.c",
|
|
||||||
"musl/src/math/sincos.c",
|
|
||||||
"musl/src/math/sincosf.c",
|
|
||||||
"musl/src/math/sincosl.c",
|
"musl/src/math/sincosl.c",
|
||||||
"musl/src/math/__sindf.c",
|
"musl/src/math/__sindf.c",
|
||||||
"musl/src/math/sinf.c",
|
|
||||||
"musl/src/math/sinh.c",
|
"musl/src/math/sinh.c",
|
||||||
"musl/src/math/sinhf.c",
|
"musl/src/math/sinhf.c",
|
||||||
"musl/src/math/sinhl.c",
|
"musl/src/math/sinhl.c",
|
||||||
|
|
@ -1210,9 +1204,7 @@ const src_files = [_][]const u8{
|
||||||
"musl/src/math/sqrtf.c",
|
"musl/src/math/sqrtf.c",
|
||||||
"musl/src/math/sqrtl.c",
|
"musl/src/math/sqrtl.c",
|
||||||
"musl/src/math/__tan.c",
|
"musl/src/math/__tan.c",
|
||||||
"musl/src/math/tan.c",
|
|
||||||
"musl/src/math/__tandf.c",
|
"musl/src/math/__tandf.c",
|
||||||
"musl/src/math/tanf.c",
|
|
||||||
"musl/src/math/tanh.c",
|
"musl/src/math/tanh.c",
|
||||||
"musl/src/math/tanhf.c",
|
"musl/src/math/tanhf.c",
|
||||||
"musl/src/math/tanhl.c",
|
"musl/src/math/tanhl.c",
|
||||||
|
|
|
||||||
|
|
@ -728,9 +728,7 @@ const libc_top_half_src_files = [_][]const u8{
|
||||||
"musl/src/math/ceill.c",
|
"musl/src/math/ceill.c",
|
||||||
"musl/src/math/copysignl.c",
|
"musl/src/math/copysignl.c",
|
||||||
"musl/src/math/__cos.c",
|
"musl/src/math/__cos.c",
|
||||||
"musl/src/math/cos.c",
|
|
||||||
"musl/src/math/__cosdf.c",
|
"musl/src/math/__cosdf.c",
|
||||||
"musl/src/math/cosf.c",
|
|
||||||
"musl/src/math/coshl.c",
|
"musl/src/math/coshl.c",
|
||||||
"musl/src/math/__cosl.c",
|
"musl/src/math/__cosl.c",
|
||||||
"musl/src/math/cosl.c",
|
"musl/src/math/cosl.c",
|
||||||
|
|
@ -871,21 +869,15 @@ const libc_top_half_src_files = [_][]const u8{
|
||||||
"musl/src/math/significand.c",
|
"musl/src/math/significand.c",
|
||||||
"musl/src/math/significandf.c",
|
"musl/src/math/significandf.c",
|
||||||
"musl/src/math/__sin.c",
|
"musl/src/math/__sin.c",
|
||||||
"musl/src/math/sin.c",
|
|
||||||
"musl/src/math/sincos.c",
|
|
||||||
"musl/src/math/sincosf.c",
|
|
||||||
"musl/src/math/sincosl.c",
|
"musl/src/math/sincosl.c",
|
||||||
"musl/src/math/__sindf.c",
|
"musl/src/math/__sindf.c",
|
||||||
"musl/src/math/sinf.c",
|
|
||||||
"musl/src/math/sinhl.c",
|
"musl/src/math/sinhl.c",
|
||||||
"musl/src/math/__sinl.c",
|
"musl/src/math/__sinl.c",
|
||||||
"musl/src/math/sinl.c",
|
"musl/src/math/sinl.c",
|
||||||
"musl/src/math/sqrt_data.c",
|
"musl/src/math/sqrt_data.c",
|
||||||
"musl/src/math/sqrtl.c",
|
"musl/src/math/sqrtl.c",
|
||||||
"musl/src/math/__tan.c",
|
"musl/src/math/__tan.c",
|
||||||
"musl/src/math/tan.c",
|
|
||||||
"musl/src/math/__tandf.c",
|
"musl/src/math/__tandf.c",
|
||||||
"musl/src/math/tanf.c",
|
|
||||||
"musl/src/math/tanh.c",
|
"musl/src/math/tanh.c",
|
||||||
"musl/src/math/tanhf.c",
|
"musl/src/math/tanhf.c",
|
||||||
"musl/src/math/tanhl.c",
|
"musl/src/math/tanhl.c",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue