1/* s_tanf.c -- float version of s_tan.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16#if defined(LIBM_SCCS) && !defined(lint)
17static char rcsid[] = "$NetBSD: s_tanf.c,v 1.4 1995/05/10 20:48:20 jtc Exp $";
18#endif
19
20#include <errno.h>
21#include <math.h>
22#include <math_private.h>
23#include <libm-alias-float.h>
24#include "s_sincosf.h"
25
26/* Reduce range of X to a multiple of PI/2. The modulo result is between
27 -PI/4 and PI/4 and returned as a high part y[0] and a low part y[1].
28 The low bit in the return value indicates the first or 2nd half of tanf. */
29static inline int32_t
30rem_pio2f (float x, float *y)
31{
32 double dx = x;
33 int n;
34 const sincos_t *p = &__sincosf_table[0];
35
36 if (__glibc_likely (abstop12 (x) < abstop12 (120.0f)))
37 dx = reduce_fast (dx, p, &n);
38 else
39 {
40 uint32_t xi = asuint (x);
41 int sign = xi >> 31;
42
43 dx = reduce_large (xi, &n);
44 dx = sign ? -dx : dx;
45 }
46
47 y[0] = dx;
48 y[1] = dx - y[0];
49 return n;
50}
51
52float __tanf(float x)
53{
54 float y[2],z=0.0;
55 int32_t n, ix;
56
57 GET_FLOAT_WORD(ix,x);
58
59 /* |x| ~< pi/4 */
60 ix &= 0x7fffffff;
61 if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1);
62
63 /* tan(Inf or NaN) is NaN */
64 else if (ix>=0x7f800000) {
65 if (ix==0x7f800000)
66 __set_errno (EDOM);
67 return x-x; /* NaN */
68 }
69
70 /* argument reduction needed */
71 else {
72 n = rem_pio2f(x,y);
73 return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
74 -1 -- n odd */
75 }
76}
77libm_alias_float (__tan, tan)
78