Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / basis / Real / Math-fns.h
1
2 #define unaryReal(g, h) \
3 MLTON_CODEGEN_MATHFN(Real64_t h(Real64_t x);) \
4 MLTON_CODEGEN_STATIC_INLINE \
5 Real64_t Real64_##g (Real64_t x) { \
6 return h (x); \
7 } \
8 MLTON_CODEGEN_MATHFN(Real32_t h##f(Real32_t x);) \
9 MLTON_CODEGEN_STATIC_INLINE \
10 Real32_t Real32_##g (Real32_t x) { \
11 return h##f (x); \
12 }
13 unaryReal(abs, fabs)
14 unaryReal(realCeil, ceil)
15 unaryReal(realFloor, floor)
16 unaryReal(realTrunc, trunc)
17 unaryReal(round, rint)
18 #undef unaryReal
19
20 #define binaryReal(g, h) \
21 MLTON_CODEGEN_MATHFN(Real64_t h(Real64_t x, Real64_t y);) \
22 MLTON_CODEGEN_STATIC_INLINE \
23 Real64_t Real64_Math_##g (Real64_t x, Real64_t y) { \
24 return h (x, y); \
25 } \
26 MLTON_CODEGEN_MATHFN(Real32_t h##f(Real32_t x, Real32_t y);) \
27 MLTON_CODEGEN_STATIC_INLINE \
28 Real32_t Real32_Math_##g (Real32_t x, Real32_t y) { \
29 return h##f (x, y); \
30 }
31 binaryReal(atan2, atan2)
32 binaryReal(pow, pow)
33 #undef binaryReal
34
35 #define unaryReal(g, h) \
36 MLTON_CODEGEN_MATHFN(Real64_t h(Real64_t x);) \
37 MLTON_CODEGEN_STATIC_INLINE \
38 Real64_t Real64_Math_##g (Real64_t x) { \
39 return h (x); \
40 } \
41 MLTON_CODEGEN_MATHFN(Real32_t h##f(Real32_t x);) \
42 MLTON_CODEGEN_STATIC_INLINE \
43 Real32_t Real32_Math_##g (Real32_t x) { \
44 return h##f (x); \
45 }
46 unaryReal(acos, acos)
47 unaryReal(asin, asin)
48 unaryReal(atan, atan)
49 unaryReal(cos, cos)
50 unaryReal(cosh, cosh)
51 unaryReal(exp, exp)
52 unaryReal(ln, log)
53 unaryReal(log10, log10)
54 unaryReal(sin, sin)
55 unaryReal(sinh, sinh)
56 unaryReal(sqrt, sqrt)
57 unaryReal(tan, tan)
58 unaryReal(tanh, tanh)
59 #undef unaryReal
60
61 #define binaryRealIntRef(g, h) \
62 MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, int* ip);) \
63 MLTON_CODEGEN_STATIC_INLINE \
64 Real64_t Real64_##g (Real64_t x, Ref(C_Int_t) i) { \
65 return h (x, (int*)i); \
66 } \
67 MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, int* ip);) \
68 MLTON_CODEGEN_STATIC_INLINE \
69 Real32_t Real32_##g (Real32_t x, Ref(C_Int_t) i) { \
70 return h##f (x, (int*)i); \
71 }
72 binaryRealIntRef(frexp, frexp)
73 #undef binaryRealIntRef
74
75 #define binaryRealInt(g, h) \
76 MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, int i);) \
77 MLTON_CODEGEN_STATIC_INLINE \
78 Real64_t Real64_##g (Real64_t x, C_Int_t i) { \
79 return h (x, i); \
80 } \
81 MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, int i);) \
82 MLTON_CODEGEN_STATIC_INLINE \
83 Real32_t Real32_##g (Real32_t x, C_Int_t i) { \
84 return h##f (x, i); \
85 }
86 binaryRealInt(ldexp, ldexp)
87 #undef binaryRealInt
88
89 #if (defined (__hppa__) || defined (__sparc__))
90 #define binaryRealRealRef(g, h) \
91 MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, Real32_t *yp);) \
92 MLTON_CODEGEN_STATIC_INLINE \
93 Real32_t Real32_##g (Real32_t x, Ref(Real32_t) yp) { \
94 /* Real32_t r, res; */ \
95 /* r = Real32_fetch (yp); */ \
96 /* res = h##f (x, &r); */ \
97 /* Real32_store (yp, r); */ \
98 /* return res; */ \
99 return h##f (x, (Real32_t*)yp); \
100 } \
101 MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, Real64_t *yp);) \
102 MLTON_CODEGEN_STATIC_INLINE \
103 Real64_t Real64_##g (Real64_t x, Ref(Real64_t) yp) { \
104 Real64_t r, res; \
105 /* r = Real64_fetch (yp); */ \
106 res = h (x, &r); \
107 Real64_store (yp, r); \
108 return res; \
109 }
110 #else
111 #define binaryRealRealRef(g, h) \
112 MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, Real32_t *yp);) \
113 MLTON_CODEGEN_STATIC_INLINE \
114 Real32_t Real32_##g (Real32_t x, Ref(Real32_t) yp) { \
115 return h##f (x, (Real32_t*)yp); \
116 } \
117 MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, Real64_t *yp);) \
118 MLTON_CODEGEN_STATIC_INLINE \
119 Real64_t Real64_##g (Real64_t x, Ref(Real64_t) yp) { \
120 return h (x, (Real64_t*)yp); \
121 }
122 #endif
123 binaryRealRealRef(modf, modf)
124 #undef binaryRealRealRef