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_sin.c -- float version of s_sin.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__
sinf(float x)28 	float sinf(float x)
29 #else
30 	float sinf(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 <= 0x3f490fd8) return __kernel_sinf(x,z,0);
42 
43     /* sin(Inf or NaN) is NaN */
44 	else if (!FLT_UWORD_IS_FINITE(ix)) return x-x;
45 
46     /* argument reduction needed */
47 	else {
48 	    n = __ieee754_rem_pio2f(x,y);
49 	    switch(n&3) {
50 		case 0: return  __kernel_sinf(y[0],y[1],1);
51 		case 1: return  __kernel_cosf(y[0],y[1]);
52 		case 2: return -__kernel_sinf(y[0],y[1],1);
53 		default:
54 			return -__kernel_cosf(y[0],y[1]);
55 	    }
56 	}
57 }
58 
59 #ifdef _DOUBLE_IS_32BITS
60 
61 #ifdef __STDC__
sin(double x)62 	double sin(double x)
63 #else
64 	double sin(x)
65 	double x;
66 #endif
67 {
68 	return (double) sinf((float) x);
69 }
70 
71 #endif /* defined(_DOUBLE_IS_32BITS) */
72