2 * Single-precision cos function.
4 * Copyright (c) 2018-2019, Arm Limited.
5 * SPDX-License-Identifier: MIT
10 #include "math_config.h"
13 /* Fast cosf implementation. Worst-case ULP is 0.5607, maximum relative
14 error is 0.5303 * 2^-23. A single-step range reduction is used for
15 small values. Large inputs have their range reduced using fast integer
23 const sincos_t *p = &__sincosf_table[0];
25 if (abstop12 (y) < abstop12 (pio4))
29 if (unlikely (abstop12 (y) < abstop12 (0x1p-12f)))
32 return sinf_poly (x, x2, p, 1);
34 else if (likely (abstop12 (y) < abstop12 (120.0f)))
36 x = reduce_fast (x, p, &n);
38 /* Setup the signs for sin and cos. */
42 p = &__sincosf_table[1];
44 return sinf_poly (x * s, x * x, p, n ^ 1);
46 else if (abstop12 (y) < abstop12 (INFINITY))
48 uint32_t xi = asuint (y);
51 x = reduce_large (xi, &n);
53 /* Setup signs for sin and cos - include original sign. */
54 s = p->sign[(n + sign) & 3];
57 p = &__sincosf_table[1];
59 return sinf_poly (x * s, x * x, p, n ^ 1);
62 return __math_invalidf (y);