1
|
1
|
|
2 /**
|
|
3 * C's <math.h>
|
|
4 * Authors: Walter Bright, Digital Mars, www.digitalmars.com
|
|
5 * License: Public Domain
|
|
6 * Macros:
|
|
7 * WIKI=Phobos/StdCMath
|
|
8 */
|
|
9
|
|
10 module std.c.math;
|
|
11
|
|
12 extern (C):
|
|
13
|
|
14 alias float float_t; ///
|
|
15 alias double double_t; ///
|
|
16
|
|
17 const double HUGE_VAL = double.infinity; ///
|
|
18 const float HUGE_VALF = float.infinity; /// ditto
|
|
19 const real HUGE_VALL = real.infinity; /// ditto
|
|
20
|
|
21 const float INFINITY = float.infinity; ///
|
|
22 const float NAN = float.nan; ///
|
|
23
|
|
24 enum
|
|
25 {
|
|
26 FP_NANS, // extension
|
|
27 FP_NANQ, // extension
|
|
28 FP_INFINITE, ///
|
|
29 FP_NAN = FP_NANQ, ///
|
|
30 FP_NORMAL = 3, ///
|
|
31 FP_SUBNORMAL = 4, ///
|
|
32 FP_ZERO = 5, ///
|
|
33 FP_EMPTY = 6, // extension
|
|
34 FP_UNSUPPORTED = 7, // extension
|
|
35 }
|
|
36
|
|
37 enum
|
|
38 {
|
|
39 FP_FAST_FMA = 0, ///
|
|
40 FP_FAST_FMAF = 0, ///
|
|
41 FP_FAST_FMAL = 0, ///
|
|
42 }
|
|
43
|
|
44 const int FP_ILOGB0 = int.min; ///
|
|
45 const int FP_ILOGBNAN = int.min; ///
|
|
46
|
|
47 const int MATH_ERRNO = 1; ///
|
|
48 const int MATH_ERREXCEPT = 2; ///
|
|
49 const int math_errhandling = MATH_ERRNO | MATH_ERREXCEPT; ///
|
|
50
|
|
51 double acos(double x); ///
|
|
52 float acosf(float x); /// ditto
|
|
53 real acosl(real x); /// ditto
|
|
54
|
|
55 double asin(double x); ///
|
|
56 float asinf(float x); /// ditto
|
|
57 real asinl(real x); /// ditto
|
|
58
|
|
59 double atan(double x); ///
|
|
60 float atanf(float x); /// ditto
|
|
61 real atanl(real x); /// ditto
|
|
62
|
|
63 double atan2(double y, double x); ///
|
|
64 float atan2f(float y, float x); /// ditto
|
|
65 real atan2l(real y, real x); /// ditto
|
|
66
|
|
67 double cos(double x); ///
|
|
68 float cosf(float x); /// ditto
|
|
69 real cosl(real x); /// ditto
|
|
70
|
|
71 double sin(double x); ///
|
|
72 float sinf(float x); /// ditto
|
|
73 real sinl(real x); /// ditto
|
|
74
|
|
75 double tan(double x); ///
|
|
76 float tanf(float x); /// ditto
|
|
77 real tanl(real x); /// ditto
|
|
78
|
|
79 double acosh(double x); ///
|
|
80 float acoshf(float x); /// ditto
|
|
81 real acoshl(real x); /// ditto
|
|
82
|
|
83 double asinh(double x); ///
|
|
84 float asinhf(float x); /// ditto
|
|
85 real asinhl(real x); /// ditto
|
|
86
|
|
87 double atanh(double x); ///
|
|
88 float atanhf(float x); /// ditto
|
|
89 real atanhl(real x); /// ditto
|
|
90
|
|
91 double cosh(double x); ///
|
|
92 float coshf(float x); /// ditto
|
|
93 real coshl(real x); /// ditto
|
|
94
|
|
95 double sinh(double x); ///
|
|
96 float sinhf(float x); /// ditto
|
|
97 real sinhl(real x); /// ditto
|
|
98
|
|
99 double tanh(double x); ///
|
|
100 float tanhf(float x); /// ditto
|
|
101 real tanhl(real x); /// ditto
|
|
102
|
|
103 double exp(double x); ///
|
|
104 float expf(float x); /// ditto
|
|
105 real expl(real x); /// ditto
|
|
106
|
|
107 double exp2(double x); ///
|
|
108 float exp2f(float x); /// ditto
|
|
109 real exp2l(real x); /// ditto
|
|
110
|
|
111 double expm1(double x); ///
|
|
112 float expm1f(float x); /// ditto
|
|
113 real expm1l(real x); /// ditto
|
|
114
|
|
115 double frexp(double value, int *exp); ///
|
|
116 float frexpf(float value, int *exp); /// ditto
|
|
117 real frexpl(real value, int *exp); /// ditto
|
|
118
|
|
119 int ilogb(double x); ///
|
|
120 int ilogbf(float x); /// ditto
|
|
121 int ilogbl(real x); /// ditto
|
|
122
|
|
123 double ldexp(double x, int exp); ///
|
|
124 float ldexpf(float x, int exp); /// ditto
|
|
125 real ldexpl(real x, int exp); /// ditto
|
|
126
|
|
127 double log(double x); ///
|
|
128 float logf(float x); /// ditto
|
|
129 real logl(real x); /// ditto
|
|
130
|
|
131 double log10(double x); ///
|
|
132 float log10f(float x); /// ditto
|
|
133 real log10l(real x); /// ditto
|
|
134
|
|
135 double log1p(double x); ///
|
|
136 float log1pf(float x); /// ditto
|
|
137 real log1pl(real x); /// ditto
|
|
138
|
|
139 double log2(double x); ///
|
|
140 float log2f(float x); /// ditto
|
|
141 real log2l(real x); /// ditto
|
|
142
|
|
143 double logb(double x); ///
|
|
144 float logbf(float x); /// ditto
|
|
145 real logbl(real x); /// ditto
|
|
146
|
|
147 double modf(double value, double *iptr); ///
|
|
148 float modff(float value, float *iptr); /// ditto
|
|
149 real modfl(real value, real *iptr); /// ditto
|
|
150
|
|
151 double scalbn(double x, int n); ///
|
|
152 float scalbnf(float x, int n); /// ditto
|
|
153 real scalbnl(real x, int n); /// ditto
|
|
154
|
|
155 double scalbln(double x, int n); ///
|
|
156 float scalblnf(float x, int n); /// ditto
|
|
157 real scalblnl(real x, int n); /// ditto
|
|
158
|
|
159 double cbrt(double x); ///
|
|
160 float cbrtf(float x); /// ditto
|
|
161 real cbrtl(real x); /// ditto
|
|
162
|
|
163 double fabs(double x); ///
|
|
164 float fabsf(float x); /// ditto
|
|
165 real fabsl(real x); /// ditto
|
|
166
|
|
167 double hypot(double x, double y); ///
|
|
168 float hypotf(float x, float y); /// ditto
|
|
169 real hypotl(real x, real y); /// ditto
|
|
170
|
|
171 double pow(double x, double y); ///
|
|
172 float powf(float x, float y); /// ditto
|
|
173 real powl(real x, real y); /// ditto
|
|
174
|
|
175 double sqrt(double x); ///
|
|
176 float sqrtf(float x); /// ditto
|
|
177 real sqrtl(real x); /// ditto
|
|
178
|
|
179 double erf(double x); ///
|
|
180 float erff(float x); /// ditto
|
|
181 real erfl(real x); /// ditto
|
|
182
|
|
183 double erfc(double x); ///
|
|
184 float erfcf(float x); /// ditto
|
|
185 real erfcl(real x); /// ditto
|
|
186
|
|
187 double lgamma(double x); ///
|
|
188 float lgammaf(float x); /// ditto
|
|
189 real lgammal(real x); /// ditto
|
|
190
|
|
191 double tgamma(double x); ///
|
|
192 float tgammaf(float x); /// ditto
|
|
193 real tgammal(real x); /// ditto
|
|
194
|
|
195 double ceil(double x); ///
|
|
196 float ceilf(float x); /// ditto
|
|
197 real ceill(real x); /// ditto
|
|
198
|
|
199 double floor(double x); ///
|
|
200 float floorf(float x); /// ditto
|
|
201 real floorl(real x); /// ditto
|
|
202
|
|
203 double nearbyint(double x); ///
|
|
204 float nearbyintf(float x); /// ditto
|
|
205 real nearbyintl(real x); /// ditto
|
|
206
|
|
207 double rint(double x); ///
|
|
208 float rintf(float x); /// ditto
|
|
209 real rintl(real x); /// ditto
|
|
210
|
|
211 int lrint(double x); ///
|
|
212 int lrintf(float x); /// ditto
|
|
213 int lrintl(real x); /// ditto
|
|
214
|
|
215 long llrint(double x); ///
|
|
216 long llrintf(float x); /// ditto
|
|
217 long llrintl(real x); /// ditto
|
|
218
|
|
219 double round(double x); ///
|
|
220 float roundf(float x); /// ditto
|
|
221 real roundl(real x); /// ditto
|
|
222
|
|
223 int lround(double x); ///
|
|
224 int lroundf(float x); /// ditto
|
|
225 int lroundl(real x); /// ditto
|
|
226
|
|
227 long llround(double x); ///
|
|
228 long llroundf(float x); /// ditto
|
|
229 long llroundl(real x); /// ditto
|
|
230
|
|
231 double trunc(double x); ///
|
|
232 float truncf(float x); /// ditto
|
|
233 real truncl(real x); /// ditto
|
|
234
|
|
235 double fmod(double x, double y); ///
|
|
236 float fmodf(float x, float y); /// ditto
|
|
237 real fmodl(real x, real y); /// ditto
|
|
238
|
|
239 double remainder(double x, double y); ///
|
|
240 float remainderf(float x, float y); /// ditto
|
|
241 real remainderl(real x, real y); /// ditto
|
|
242
|
|
243 double remquo(double x, double y, int *quo); ///
|
|
244 float remquof(float x, float y, int *quo); /// ditto
|
|
245 real remquol(real x, real y, int *quo); /// ditto
|
|
246
|
|
247 double copysign(double x, double y); ///
|
|
248 float copysignf(float x, float y); /// ditto
|
|
249 real copysignl(real x, real y); /// ditto
|
|
250
|
|
251 double nan(char *tagp); ///
|
|
252 float nanf(char *tagp); /// ditto
|
|
253 real nanl(char *tagp); /// ditto
|
|
254
|
|
255 double nextafter(double x, double y); ///
|
|
256 float nextafterf(float x, float y); /// ditto
|
|
257 real nextafterl(real x, real y); /// ditto
|
|
258
|
|
259 double nexttoward(double x, real y); ///
|
|
260 float nexttowardf(float x, real y); /// ditto
|
|
261 real nexttowardl(real x, real y); /// ditto
|
|
262
|
|
263 double fdim(double x, double y); ///
|
|
264 float fdimf(float x, float y); /// ditto
|
|
265 real fdiml(real x, real y); /// ditto
|
|
266
|
|
267 double fmax(double x, double y); ///
|
|
268 float fmaxf(float x, float y); /// ditto
|
|
269 real fmaxl(real x, real y); /// ditto
|
|
270
|
|
271 double fmin(double x, double y); ///
|
|
272 float fminf(float x, float y); /// ditto
|
|
273 real fminl(real x, real y); /// ditto
|
|
274
|
|
275 double fma(double x, double y, double z); ///
|
|
276 float fmaf(float x, float y, float z); /// ditto
|
|
277 real fmal(real x, real y, real z); /// ditto
|
|
278
|
|
279 ///
|
|
280 int isgreater(real x, real y) { return !(x !> y); }
|
|
281 ///
|
|
282 int isgreaterequal(real x, real y) { return !(x !>= y); }
|
|
283 ///
|
|
284 int isless(real x, real y) { return !(x !< y); }
|
|
285 ///
|
|
286 int islessequal(real x, real y) { return !(x !<= y); }
|
|
287 ///
|
|
288 int islessgreater(real x, real y) { return !(x !<> y); }
|
|
289 ///
|
|
290 int isunordered(real x, real y) { return (x !<>= y); }
|
|
291
|