1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * These math functions are taken from newlib-nano-2, the newlib/libm/math
5  * directory, available from https://github.com/32bitmicro/newlib-nano-2.
6  *
7  * Appropriate copyright headers are reproduced below.
8  */
9 
10 /* sf_tan.c -- float version of s_tan.c.
11  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
12  */
13 
14 /*
15  * ====================================================
16  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
17  *
18  * Developed at SunPro, a Sun Microsystems, Inc. business.
19  * Permission to use, copy, modify, and distribute this
20  * software is freely granted, provided that this notice
21  * is preserved.
22  * ====================================================
23  */
24 
25 #include "fdlibm.h"
26 
27 #ifdef __STDC__
tanf(float x)28 	float tanf(float x)
29 #else
30 	float tanf(x)
31 	float x;
32 #endif
33 {
34 	float y[2],z=0.0;
35 	__int32_t n,ix;
36 
37 	GET_FLOAT_WORD(ix,x);
38 
39     /* |x| ~< pi/4 */
40 	ix &= 0x7fffffff;
41 	if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1);
42 
43     /* tan(Inf or NaN) is NaN */
44 	else if (!FLT_UWORD_IS_FINITE(ix)) return x-x;		/* NaN */
45 
46     /* argument reduction needed */
47 	else {
48 	    n = __ieee754_rem_pio2f(x,y);
49 	    return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
50 							      -1 -- n odd */
51 	}
52 }
53 
54 #ifdef _DOUBLE_IS_32BITS
55 
56 #ifdef __STDC__
tan(double x)57 	double tan(double x)
58 #else
59 	double tan(x)
60 	double x;
61 #endif
62 {
63 	return (double) tanf((float) x);
64 }
65 
66 #endif /* defined(_DOUBLE_IS_32BITS) */
67