mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Merge pull request #24034 from papparapa/remove-musl-trigonometric-function
libc: replace musl's and MinGW's trigonometric functions with compiler_rt's
This commit is contained in:
commit
597dd328e3
19 changed files with 2 additions and 802 deletions
4
lib/libc/mingw/math/arm/sincos.S
vendored
4
lib/libc/mingw/math/arm/sincos.S
vendored
|
|
@ -8,11 +8,9 @@
|
|||
.file "sincos.S"
|
||||
.text
|
||||
.align 2
|
||||
.globl __MINGW_USYMBOL(sincos)
|
||||
/* zig patch: remove sincos symbol because sincos in compiler_rt is used instead */
|
||||
.globl __MINGW_USYMBOL(sincosl)
|
||||
.def __MINGW_USYMBOL(sincos); .scl 2; .type 32; .endef
|
||||
.def __MINGW_USYMBOL(sincosl); .scl 2; .type 32; .endef
|
||||
__MINGW_USYMBOL(sincos):
|
||||
__MINGW_USYMBOL(sincosl):
|
||||
push {r4, r5, r11, lr}
|
||||
add r11, sp, #8
|
||||
|
|
|
|||
29
lib/libc/mingw/math/arm/sincosf.S
vendored
29
lib/libc/mingw/math/arm/sincosf.S
vendored
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* 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 <_mingw_mac.h>
|
||||
|
||||
.file "sincosf.S"
|
||||
.text
|
||||
.align 2
|
||||
.globl __MINGW_USYMBOL(sincosf)
|
||||
.def __MINGW_USYMBOL(sincosf); .scl 2; .type 32; .endef
|
||||
__MINGW_USYMBOL(sincosf):
|
||||
push {r4, r5, r11, lr}
|
||||
add r11, sp, #8
|
||||
vpush {d8}
|
||||
|
||||
mov r4, r0
|
||||
mov r5, r1
|
||||
vmov.f32 s16, s0
|
||||
bl sinf
|
||||
vstr s0, [r4]
|
||||
|
||||
vmov.f32 s0, s16
|
||||
bl cosf
|
||||
vstr s0, [r5]
|
||||
|
||||
vpop {d8}
|
||||
pop {r4, r5, r11, pc}
|
||||
4
lib/libc/mingw/math/arm64/sincos.S
vendored
4
lib/libc/mingw/math/arm64/sincos.S
vendored
|
|
@ -8,11 +8,9 @@
|
|||
.file "sincos.S"
|
||||
.text
|
||||
.align 2
|
||||
.globl __MINGW_USYMBOL(sincos)
|
||||
/* zig patch: remove sincos symbol because sincos in compiler_rt is used instead */
|
||||
.globl __MINGW_USYMBOL(sincosl)
|
||||
.def __MINGW_USYMBOL(sincos); .scl 2; .type 32; .endef
|
||||
.def __MINGW_USYMBOL(sincosl); .scl 2; .type 32; .endef
|
||||
__MINGW_USYMBOL(sincos):
|
||||
__MINGW_USYMBOL(sincosl):
|
||||
str d8, [sp, #-32]!
|
||||
str x30, [sp, #8]
|
||||
|
|
|
|||
31
lib/libc/mingw/math/arm64/sincosf.S
vendored
31
lib/libc/mingw/math/arm64/sincosf.S
vendored
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* 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 <_mingw_mac.h>
|
||||
|
||||
.file "sincosf.S"
|
||||
.text
|
||||
.align 2
|
||||
.globl __MINGW_USYMBOL(sincosf)
|
||||
.def __MINGW_USYMBOL(sincosf); .scl 2; .type 32; .endef
|
||||
__MINGW_USYMBOL(sincosf):
|
||||
str d8, [sp, #-32]!
|
||||
str x30, [sp, #8]
|
||||
stp x19, x20, [sp, #16]
|
||||
|
||||
mov x19, x0
|
||||
mov x20, x1
|
||||
fmov s8, s0
|
||||
bl sinf
|
||||
str s0, [x19]
|
||||
|
||||
fmov s0, s8
|
||||
bl cosf
|
||||
str s0, [x20]
|
||||
|
||||
ldp x19, x20, [sp, #16]
|
||||
ldr x30, [sp, #8]
|
||||
ldr d8, [sp], #32
|
||||
ret
|
||||
11
lib/libc/mingw/math/x86/cosf.c
vendored
11
lib/libc/mingw/math/x86/cosf.c
vendored
|
|
@ -1,11 +0,0 @@
|
|||
/**
|
||||
* 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>
|
||||
|
||||
float cosf(float _X)
|
||||
{
|
||||
return ((float)cos((double)_X));
|
||||
}
|
||||
52
lib/libc/mingw/math/x86/cossin.c
vendored
52
lib/libc/mingw/math/x86/cossin.c
vendored
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void sincos (double __x, double *p_sin, double *p_cos);
|
||||
void sincosf (float __x, float *p_sin, float *p_cos);
|
||||
|
||||
void sincos (double __x, double *p_sin, double *p_cos)
|
||||
{
|
||||
long double c, s;
|
||||
|
||||
__asm__ __volatile__ ("fsincos\n\t"
|
||||
"fnstsw %%ax\n\t"
|
||||
"testl $0x400, %%eax\n\t"
|
||||
"jz 1f\n\t"
|
||||
"fldpi\n\t"
|
||||
"fadd %%st(0)\n\t"
|
||||
"fxch %%st(1)\n\t"
|
||||
"2: fprem1\n\t"
|
||||
"fnstsw %%ax\n\t"
|
||||
"testl $0x400, %%eax\n\t"
|
||||
"jnz 2b\n\t"
|
||||
"fstp %%st(1)\n\t"
|
||||
"fsincos\n\t"
|
||||
"1:" : "=t" (c), "=u" (s) : "0" (__x) : "eax");
|
||||
*p_sin = (double) s;
|
||||
*p_cos = (double) c;
|
||||
}
|
||||
|
||||
void sincosf (float __x, float *p_sin, float *p_cos)
|
||||
{
|
||||
long double c, s;
|
||||
|
||||
__asm__ __volatile__ ("fsincos\n\t"
|
||||
"fnstsw %%ax\n\t"
|
||||
"testl $0x400, %%eax\n\t"
|
||||
"jz 1f\n\t"
|
||||
"fldpi\n\t"
|
||||
"fadd %%st(0)\n\t"
|
||||
"fxch %%st(1)\n\t"
|
||||
"2: fprem1\n\t"
|
||||
"fnstsw %%ax\n\t"
|
||||
"testl $0x400, %%eax\n\t"
|
||||
"jnz 2b\n\t"
|
||||
"fstp %%st(1)\n\t"
|
||||
"fsincos\n\t"
|
||||
"1:" : "=t" (c), "=u" (s) : "0" (__x) : "eax");
|
||||
*p_sin = (float) s;
|
||||
*p_cos = (float) c;
|
||||
}
|
||||
11
lib/libc/mingw/math/x86/sinf.c
vendored
11
lib/libc/mingw/math/x86/sinf.c
vendored
|
|
@ -1,11 +0,0 @@
|
|||
/**
|
||||
* 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>
|
||||
|
||||
float sinf(float _X)
|
||||
{
|
||||
return ((float) sin ((double) _X));
|
||||
}
|
||||
11
lib/libc/mingw/math/x86/tanf.c
vendored
11
lib/libc/mingw/math/x86/tanf.c
vendored
|
|
@ -1,11 +0,0 @@
|
|||
/**
|
||||
* 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>
|
||||
|
||||
float tanf(float _X)
|
||||
{
|
||||
return ((float)tan((double)_X));
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
@ -916,7 +916,6 @@ const mingw32_x86_src = [_][]const u8{
|
|||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "copysignl.S",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosl.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosl_internal.S",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cossin.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cossinl.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "exp2l.S",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expl.c",
|
||||
|
|
@ -965,11 +964,8 @@ const mingw32_x86_32_src = [_][]const u8{
|
|||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atan2f.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atanf.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "ceilf.S",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosf.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "floorf.S",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fmodf.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "sinf.c",
|
||||
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "tanf.c",
|
||||
};
|
||||
|
||||
const mingw32_arm_src = [_][]const u8{
|
||||
|
|
@ -983,7 +979,6 @@ const mingw32_arm32_src = [_][]const u8{
|
|||
"math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rint.c",
|
||||
"math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rintf.c",
|
||||
"math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincos.S",
|
||||
"math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincosf.S",
|
||||
};
|
||||
|
||||
const mingw32_arm64_src = [_][]const u8{
|
||||
|
|
@ -992,7 +987,6 @@ const mingw32_arm64_src = [_][]const u8{
|
|||
"math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rint.c",
|
||||
"math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rintf.c",
|
||||
"math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincos.S",
|
||||
"math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincosf.S",
|
||||
};
|
||||
|
||||
const mingw32_winpthreads_src = [_][]const u8{
|
||||
|
|
|
|||
|
|
@ -886,9 +886,7 @@ const src_files = [_][]const u8{
|
|||
"musl/src/math/copysignf.c",
|
||||
"musl/src/math/copysignl.c",
|
||||
"musl/src/math/__cos.c",
|
||||
"musl/src/math/cos.c",
|
||||
"musl/src/math/__cosdf.c",
|
||||
"musl/src/math/cosf.c",
|
||||
"musl/src/math/cosh.c",
|
||||
"musl/src/math/coshf.c",
|
||||
"musl/src/math/coshl.c",
|
||||
|
|
@ -1194,12 +1192,8 @@ const src_files = [_][]const u8{
|
|||
"musl/src/math/significand.c",
|
||||
"musl/src/math/significandf.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/__sindf.c",
|
||||
"musl/src/math/sinf.c",
|
||||
"musl/src/math/sinh.c",
|
||||
"musl/src/math/sinhf.c",
|
||||
"musl/src/math/sinhl.c",
|
||||
|
|
@ -1210,9 +1204,7 @@ const src_files = [_][]const u8{
|
|||
"musl/src/math/sqrtf.c",
|
||||
"musl/src/math/sqrtl.c",
|
||||
"musl/src/math/__tan.c",
|
||||
"musl/src/math/tan.c",
|
||||
"musl/src/math/__tandf.c",
|
||||
"musl/src/math/tanf.c",
|
||||
"musl/src/math/tanh.c",
|
||||
"musl/src/math/tanhf.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/copysignl.c",
|
||||
"musl/src/math/__cos.c",
|
||||
"musl/src/math/cos.c",
|
||||
"musl/src/math/__cosdf.c",
|
||||
"musl/src/math/cosf.c",
|
||||
"musl/src/math/coshl.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/significandf.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/__sindf.c",
|
||||
"musl/src/math/sinf.c",
|
||||
"musl/src/math/sinhl.c",
|
||||
"musl/src/math/__sinl.c",
|
||||
"musl/src/math/sinl.c",
|
||||
"musl/src/math/sqrt_data.c",
|
||||
"musl/src/math/sqrtl.c",
|
||||
"musl/src/math/__tan.c",
|
||||
"musl/src/math/tan.c",
|
||||
"musl/src/math/__tandf.c",
|
||||
"musl/src/math/tanf.c",
|
||||
"musl/src/math/tanh.c",
|
||||
"musl/src/math/tanhf.c",
|
||||
"musl/src/math/tanhl.c",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue