1 // Portions of this file are extracted from musl-1.1.16 src/internal/libm.h
2 
3 /* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */
4 /*
5  * ====================================================
6  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7  *
8  * Developed at SunPro, a Sun Microsystems, Inc. business.
9  * Permission to use, copy, modify, and distribute this
10  * software is freely granted, provided that this notice
11  * is preserved.
12  * ====================================================
13  */
14 
15 #include <stdint.h>
16 #include <math.h>
17 
18 #define FLT_EVAL_METHOD 0
19 
20 #define FORCE_EVAL(x) do {                        \
21 	if (sizeof(x) == sizeof(float)) {         \
22 		volatile float __x;               \
23 		__x = (x);                        \
24                 (void)__x;                        \
25 	} else if (sizeof(x) == sizeof(double)) { \
26 		volatile double __x;              \
27 		__x = (x);                        \
28                 (void)__x;                        \
29 	} else {                                  \
30 		volatile long double __x;         \
31 		__x = (x);                        \
32                 (void)__x;                        \
33 	}                                         \
34 } while(0)
35 
36 /* Get two 32 bit ints from a double.  */
37 #define EXTRACT_WORDS(hi,lo,d)                    \
38 do {                                              \
39   union {double f; uint64_t i;} __u;              \
40   __u.f = (d);                                    \
41   (hi) = __u.i >> 32;                             \
42   (lo) = (uint32_t)__u.i;                         \
43 } while (0)
44 
45 /* Get the more significant 32 bit int from a double.  */
46 #define GET_HIGH_WORD(hi,d)                       \
47 do {                                              \
48   union {double f; uint64_t i;} __u;              \
49   __u.f = (d);                                    \
50   (hi) = __u.i >> 32;                             \
51 } while (0)
52 
53 /* Get the less significant 32 bit int from a double.  */
54 #define GET_LOW_WORD(lo,d)                        \
55 do {                                              \
56   union {double f; uint64_t i;} __u;              \
57   __u.f = (d);                                    \
58   (lo) = (uint32_t)__u.i;                         \
59 } while (0)
60 
61 /* Set a double from two 32 bit ints.  */
62 #define INSERT_WORDS(d,hi,lo)                     \
63 do {                                              \
64   union {double f; uint64_t i;} __u;              \
65   __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo);  \
66   (d) = __u.f;                                    \
67 } while (0)
68 
69 /* Set the more significant 32 bits of a double from an int.  */
70 #define SET_HIGH_WORD(d,hi)                       \
71 do {                                              \
72   union {double f; uint64_t i;} __u;              \
73   __u.f = (d);                                    \
74   __u.i &= 0xffffffff;                            \
75   __u.i |= (uint64_t)(hi) << 32;                  \
76   (d) = __u.f;                                    \
77 } while (0)
78 
79 /* Set the less significant 32 bits of a double from an int.  */
80 #define SET_LOW_WORD(d,lo)                        \
81 do {                                              \
82   union {double f; uint64_t i;} __u;              \
83   __u.f = (d);                                    \
84   __u.i &= 0xffffffff00000000ull;                 \
85   __u.i |= (uint32_t)(lo);                        \
86   (d) = __u.f;                                    \
87 } while (0)
88 
89 #define DBL_EPSILON 2.22044604925031308085e-16
90 
91 int __rem_pio2(double, double*);
92 int __rem_pio2_large(double*, double*, int, int, int);
93 double __sin(double, double, int);
94 double __cos(double, double);
95 double __tan(double, double, int);
96 double __expo2(double);
97