]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/flt-32/s_sincosf.c
6e34fb64595c1cefc59ed4b6dd364e32558158ab
1 /* Compute sine and cosine of argument.
2 Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <math-barriers.h>
23 #include <libm-alias-float.h>
24 #include "math_config.h"
25 #include "s_sincosf.h"
28 # define SINCOSF_FUNC __sincosf
30 # define SINCOSF_FUNC SINCOSF
33 /* Fast sincosf implementation. Worst-case ULP is 0.5607, maximum relative
34 error is 0.5303 * 2^-23. A single-step range reduction is used for
35 small values. Large inputs have their range reduced using fast integer
38 SINCOSF_FUNC (float y
, float *sinp
, float *cosp
)
43 const sincos_t
*p
= &__sincosf_table
[0];
45 if (abstop12 (y
) < abstop12 (pio4
))
49 if (__glibc_unlikely (abstop12 (y
) < abstop12 (0x1p
-12f
)))
51 /* Force underflow for tiny y. */
52 if (__glibc_unlikely (abstop12 (y
) < abstop12 (0x1p
-126f
)))
53 math_force_eval ((float)x2
);
59 sincosf_poly (x
, x2
, p
, 0, sinp
, cosp
);
61 else if (abstop12 (y
) < abstop12 (120.0f
))
63 x
= reduce_fast (x
, p
, &n
);
65 /* Setup the signs for sin and cos. */
69 p
= &__sincosf_table
[1];
71 sincosf_poly (x
* s
, x
* x
, p
, n
, sinp
, cosp
);
73 else if (__glibc_likely (abstop12 (y
) < abstop12 (INFINITY
)))
75 uint32_t xi
= asuint (y
);
78 x
= reduce_large (xi
, &n
);
80 /* Setup signs for sin and cos - include original sign. */
81 s
= p
->sign
[(n
+ sign
) & 3];
84 p
= &__sincosf_table
[1];
86 sincosf_poly (x
* s
, x
* x
, p
, n
, sinp
, cosp
);
90 /* Return NaN if Inf or NaN for both sin and cos. */
91 *sinp
= *cosp
= y
- y
;
93 /* Needed to set errno for +-Inf, the add is a hack to work
94 around a gcc register allocation issue: just passing y
95 affects code generation in the fast path (PR86901). */
96 __math_invalidf (y
+ y
);
102 libm_alias_float (__sincos
, sincos
)