Mercurial > projects > ldc
comparison tango/tango/stdc/math.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /** | |
2 * D header file for C99. | |
3 * | |
4 * Copyright: Public Domain | |
5 * License: Public Domain | |
6 * Authors: Sean Kelly, Walter Bright | |
7 * Standards: ISO/IEC 9899:1999 (E) | |
8 */ | |
9 module tango.stdc.math; | |
10 | |
11 private import tango.stdc.config; | |
12 | |
13 extern (C): | |
14 | |
15 alias float float_t; | |
16 alias double double_t; | |
17 | |
18 const double HUGE_VAL = double.infinity; | |
19 const double HUGE_VALF = float.infinity; | |
20 const double HUGE_VALL = real.infinity; | |
21 | |
22 const float INFINITY = float.infinity; | |
23 const float NAN = float.nan; | |
24 | |
25 const int FP_ILOGB0 = int.min; | |
26 const int FP_ILOGBNAN = int.min; | |
27 | |
28 const int MATH_ERRNO = 1; | |
29 const int MATH_ERREXCEPT = 2; | |
30 const int math_errhandling = MATH_ERRNO | MATH_ERREXCEPT; | |
31 | |
32 version( none ) | |
33 { | |
34 // | |
35 // these functions are all macros in C | |
36 // | |
37 | |
38 //int fpclassify(real-floating x); | |
39 int fpclassify(float x); | |
40 int fpclassify(double x); | |
41 int fpclassify(real x); | |
42 | |
43 //int isfinite(real-floating x); | |
44 int isfinite(float x); | |
45 int isfinite(double x); | |
46 int isfinite(real x); | |
47 | |
48 //int isinf(real-floating x); | |
49 int isinf(float x); | |
50 int isinf(double x); | |
51 int isinf(real x); | |
52 | |
53 //int isnan(real-floating x); | |
54 int isnan(float x); | |
55 int isnan(double x); | |
56 int isnan(real x); | |
57 | |
58 //int isnormal(real-floating x); | |
59 int isnormal(float x); | |
60 int isnormal(double x); | |
61 int isnormal(real x); | |
62 | |
63 //int signbit(real-floating x); | |
64 int signbit(float x); | |
65 int signbit(double x); | |
66 int signbit(real x); | |
67 | |
68 //int isgreater(real-floating x, real-floating y); | |
69 int isgreater(float x, float y); | |
70 int isgreater(double x, double y); | |
71 int isgreater(real x, real y); | |
72 | |
73 //int isgreaterequal(real-floating x, real-floating y); | |
74 int isgreaterequal(float x, float y); | |
75 int isgreaterequal(double x, double y); | |
76 int isgreaterequal(real x, real y); | |
77 | |
78 //int isless(real-floating x, real-floating y); | |
79 int isless(float x, float y); | |
80 int isless(double x, double y); | |
81 int isless(real x, real y); | |
82 | |
83 //int islessequal(real-floating x, real-floating y); | |
84 int islessequal(float x, float y); | |
85 int islessequal(double x, double y); | |
86 int islessequal(real x, real y); | |
87 | |
88 //int islessgreater(real-floating x, real-floating y); | |
89 int islessgreater(float x, float y); | |
90 int islessgreater(double x, double y); | |
91 int islessgreater(real x, real y); | |
92 | |
93 //int isunordered(real-floating x, real-floating y); | |
94 int isunordered(float x, float y); | |
95 int isunordered(double x, double y); | |
96 int isunordered(real x, real y); | |
97 } | |
98 | |
99 version( DigitalMars ) version( Win32 ) | |
100 version = DigitalMarsWin32; | |
101 | |
102 version( DigitalMarsWin32 ) | |
103 { | |
104 enum | |
105 { | |
106 FP_NANS = 0, | |
107 FP_NANQ = 1, | |
108 FP_INFINITE = 2, | |
109 FP_NORMAL = 3, | |
110 FP_SUBNORMAL = 4, | |
111 FP_ZERO = 5, | |
112 FP_NAN = FP_NANQ, | |
113 FP_EMPTY = 6, | |
114 FP_UNSUPPORTED = 7, | |
115 } | |
116 | |
117 enum | |
118 { | |
119 FP_FAST_FMA = 0, | |
120 FP_FAST_FMAF = 0, | |
121 FP_FAST_FMAL = 0, | |
122 } | |
123 | |
124 uint __fpclassify_f(float x); | |
125 uint __fpclassify_d(double x); | |
126 uint __fpclassify_ld(real x); | |
127 | |
128 extern (D) | |
129 { | |
130 //int fpclassify(real-floating x); | |
131 int fpclassify(float x) { return __fpclassify_f(x); } | |
132 int fpclassify(double x) { return __fpclassify_d(x); } | |
133 int fpclassify(real x) | |
134 { | |
135 return (real.sizeof == double.sizeof) | |
136 ? __fpclassify_d(x) | |
137 : __fpclassify_ld(x); | |
138 } | |
139 | |
140 //int isfinite(real-floating x); | |
141 int isfinite(float x) { return fpclassify(x) >= FP_NORMAL; } | |
142 int isfinite(double x) { return fpclassify(x) >= FP_NORMAL; } | |
143 int isfinite(real x) { return fpclassify(x) >= FP_NORMAL; } | |
144 | |
145 //int isinf(real-floating x); | |
146 int isinf(float x) { return fpclassify(x) == FP_INFINITE; } | |
147 int isinf(double x) { return fpclassify(x) == FP_INFINITE; } | |
148 int isinf(real x) { return fpclassify(x) == FP_INFINITE; } | |
149 | |
150 //int isnan(real-floating x); | |
151 int isnan(float x) { return fpclassify(x) <= FP_NANQ; } | |
152 int isnan(double x) { return fpclassify(x) <= FP_NANQ; } | |
153 int isnan(real x) { return fpclassify(x) <= FP_NANQ; } | |
154 | |
155 //int isnormal(real-floating x); | |
156 int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } | |
157 int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } | |
158 int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } | |
159 | |
160 //int signbit(real-floating x); | |
161 int signbit(float x) { return (cast(short*)&(x))[1] & 0x8000; } | |
162 int signbit(double x) { return (cast(short*)&(x))[3] & 0x8000; } | |
163 int signbit(real x) | |
164 { | |
165 return (real.sizeof == double.sizeof) | |
166 ? (cast(short*)&(x))[3] & 0x8000 | |
167 : (cast(short*)&(x))[4] & 0x8000; | |
168 } | |
169 } | |
170 } | |
171 else version( linux ) | |
172 { | |
173 enum | |
174 { | |
175 FP_NAN, | |
176 FP_INFINITE, | |
177 FP_ZERO, | |
178 FP_SUBNORMAL, | |
179 FP_NORMAL, | |
180 } | |
181 | |
182 enum | |
183 { | |
184 FP_FAST_FMA = 0, | |
185 FP_FAST_FMAF = 0, | |
186 FP_FAST_FMAL = 0, | |
187 } | |
188 | |
189 int __fpclassifyf(float x); | |
190 int __fpclassify(double x); | |
191 int __fpclassifyl(real x); | |
192 | |
193 int __finitef(float x); | |
194 int __finite(double x); | |
195 int __finitel(real x); | |
196 | |
197 int __isinff(float x); | |
198 int __isinf(double x); | |
199 int __isinfl(real x); | |
200 | |
201 int __isnanf(float x); | |
202 int __isnan(double x); | |
203 int __isnanl(real x); | |
204 | |
205 int __signbitf(float x); | |
206 int __signbit(double x); | |
207 int __signbitl(real x); | |
208 | |
209 extern (D) | |
210 { | |
211 //int fpclassify(real-floating x); | |
212 int fpclassify(float x) { return __fpclassifyf(x); } | |
213 int fpclassify(double x) { return __fpclassify(x); } | |
214 int fpclassify(real x) | |
215 { | |
216 return (real.sizeof == double.sizeof) | |
217 ? __fpclassify(x) | |
218 : __fpclassifyl(x); | |
219 } | |
220 | |
221 //int isfinite(real-floating x); | |
222 int isfinite(float x) { return __finitef(x); } | |
223 int isfinite(double x) { return __finite(x); } | |
224 int isfinite(real x) | |
225 { | |
226 return (real.sizeof == double.sizeof) | |
227 ? __finite(x) | |
228 : __finitel(x); | |
229 } | |
230 | |
231 //int isinf(real-floating x); | |
232 int isinf(float x) { return __isinff(x); } | |
233 int isinf(double x) { return __isinf(x); } | |
234 int isinf(real x) | |
235 { | |
236 return (real.sizeof == double.sizeof) | |
237 ? __isinf(x) | |
238 : __isinfl(x); | |
239 } | |
240 | |
241 //int isnan(real-floating x); | |
242 int isnan(float x) { return __isnanf(x); } | |
243 int isnan(double x) { return __isnan(x); } | |
244 int isnan(real x) | |
245 { | |
246 return (real.sizeof == double.sizeof) | |
247 ? __isnan(x) | |
248 : __isnanl(x); | |
249 } | |
250 | |
251 //int isnormal(real-floating x); | |
252 int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } | |
253 int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } | |
254 int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } | |
255 | |
256 //int signbit(real-floating x); | |
257 int signbit(float x) { return __signbitf(x); } | |
258 int signbit(double x) { return __signbit(x); } | |
259 int signbit(real x) | |
260 { | |
261 return (real.sizeof == double.sizeof) | |
262 ? __signbit(x) | |
263 : __signbitl(x); | |
264 } | |
265 } | |
266 } | |
267 else version( darwin ) | |
268 { | |
269 enum | |
270 { | |
271 FP_NAN = 1, | |
272 FP_INFINITE = 2, | |
273 FP_ZERO = 3, | |
274 FP_NORMAL = 4, | |
275 FP_SUBNORMAL = 5, | |
276 FP_SUPERNORMAL = 6 | |
277 } | |
278 | |
279 enum | |
280 { | |
281 FP_FAST_FMA = 0, | |
282 FP_FAST_FMAF = 0, | |
283 FP_FAST_FMAL = 0, | |
284 } | |
285 | |
286 int __fpclassifyf(float x); | |
287 int __fpclassifyd(double x); | |
288 int __fpclassify(real x); | |
289 | |
290 int __isfinitef(float x); | |
291 int __isfinited(double x); | |
292 int __isfinite(real x); | |
293 | |
294 int __isinff(float x); | |
295 int __isinfd(double x); | |
296 int __isinf(real x); | |
297 | |
298 int __isnanf(float x); | |
299 int __isnand(double x); | |
300 int __isnan(real x); | |
301 | |
302 int __signbitf(float x); | |
303 int __signbitd(double x); | |
304 int __signbitl(real x); | |
305 | |
306 extern (D) | |
307 { | |
308 //int fpclassify(real-floating x); | |
309 int fpclassify(float x) { return __fpclassifyf(x); } | |
310 int fpclassify(double x) { return __fpclassifyd(x); } | |
311 int fpclassify(real x) | |
312 { | |
313 return (real.sizeof == double.sizeof) | |
314 ? __fpclassifyd(x) | |
315 : __fpclassify(x); | |
316 } | |
317 | |
318 //int isfinite(real-floating x); | |
319 int isfinite(float x) { return __isfinitef(x); } | |
320 int isfinite(double x) { return __isfinited(x); } | |
321 int isfinite(real x) | |
322 { | |
323 return (real.sizeof == double.sizeof) | |
324 ? __isfinited(x) | |
325 : __isfinite(x); | |
326 } | |
327 | |
328 //int isinf(real-floating x); | |
329 int isinf(float x) { return __isinff(x); } | |
330 int isinf(double x) { return __isinfd(x); } | |
331 int isinf(real x) | |
332 { | |
333 return (real.sizeof == double.sizeof) | |
334 ? __isinfd(x) | |
335 : __isinf(x); | |
336 } | |
337 | |
338 //int isnan(real-floating x); | |
339 int isnan(float x) { return __isnanf(x); } | |
340 int isnan(double x) { return __isnand(x); } | |
341 int isnan(real x) | |
342 { | |
343 return (real.sizeof == double.sizeof) | |
344 ? __isnand(x) | |
345 : __isnan(x); | |
346 } | |
347 | |
348 //int isnormal(real-floating x); | |
349 int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } | |
350 int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } | |
351 int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } | |
352 | |
353 //int signbit(real-floating x); | |
354 int signbit(float x) { return __signbitf(x); } | |
355 int signbit(double x) { return __signbitd(x); } | |
356 int signbit(real x) | |
357 { | |
358 return (real.sizeof == double.sizeof) | |
359 ? __signbitd(x) | |
360 : __signbitl(x); | |
361 } | |
362 } | |
363 } | |
364 | |
365 extern (D) | |
366 { | |
367 //int isgreater(real-floating x, real-floating y); | |
368 int isgreater(float x, float y) { return !(x !> y); } | |
369 int isgreater(double x, double y) { return !(x !> y); } | |
370 int isgreater(real x, real y) { return !(x !> y); } | |
371 | |
372 //int isgreaterequal(real-floating x, real-floating y); | |
373 int isgreaterequal(float x, float y) { return !(x !>= y); } | |
374 int isgreaterequal(double x, double y) { return !(x !>= y); } | |
375 int isgreaterequal(real x, real y) { return !(x !>= y); } | |
376 | |
377 //int isless(real-floating x, real-floating y); | |
378 int isless(float x, float y) { return !(x !< y); } | |
379 int isless(double x, double y) { return !(x !< y); } | |
380 int isless(real x, real y) { return !(x !< y); } | |
381 | |
382 //int islessequal(real-floating x, real-floating y); | |
383 int islessequal(float x, float y) { return !(x !<= y); } | |
384 int islessequal(double x, double y) { return !(x !<= y); } | |
385 int islessequal(real x, real y) { return !(x !<= y); } | |
386 | |
387 //int islessgreater(real-floating x, real-floating y); | |
388 int islessgreater(float x, float y) { return !(x !<> y); } | |
389 int islessgreater(double x, double y) { return !(x !<> y); } | |
390 int islessgreater(real x, real y) { return !(x !<> y); } | |
391 | |
392 //int isunordered(real-floating x, real-floating y); | |
393 int isunordered(float x, float y) { return (x !<>= y); } | |
394 int isunordered(double x, double y) { return (x !<>= y); } | |
395 int isunordered(real x, real y) { return (x !<>= y); } | |
396 } | |
397 | |
398 double acos(double x); | |
399 float acosf(float x); | |
400 real acosl(real x); | |
401 | |
402 double asin(double x); | |
403 float asinf(float x); | |
404 real asinl(real x); | |
405 | |
406 double atan(double x); | |
407 float atanf(float x); | |
408 real atanl(real x); | |
409 | |
410 double atan2(double y, double x); | |
411 float atan2f(float y, float x); | |
412 real atan2l(real y, real x); | |
413 | |
414 double cos(double x); | |
415 float cosf(float x); | |
416 real cosl(real x); | |
417 | |
418 double sin(double x); | |
419 float sinf(float x); | |
420 real sinl(real x); | |
421 | |
422 double tan(double x); | |
423 float tanf(float x); | |
424 real tanl(real x); | |
425 | |
426 double acosh(double x); | |
427 float acoshf(float x); | |
428 real acoshl(real x); | |
429 | |
430 double asinh(double x); | |
431 float asinhf(float x); | |
432 real asinhl(real x); | |
433 | |
434 double atanh(double x); | |
435 float atanhf(float x); | |
436 real atanhl(real x); | |
437 | |
438 double cosh(double x); | |
439 float coshf(float x); | |
440 real coshl(real x); | |
441 | |
442 double sinh(double x); | |
443 float sinhf(float x); | |
444 real sinhl(real x); | |
445 | |
446 double tanh(double x); | |
447 float tanhf(float x); | |
448 real tanhl(real x); | |
449 | |
450 double exp(double x); | |
451 float expf(float x); | |
452 real expl(real x); | |
453 | |
454 double exp2(double x); | |
455 float exp2f(float x); | |
456 real exp2l(real x); | |
457 | |
458 double expm1(double x); | |
459 float expm1f(float x); | |
460 real expm1l(real x); | |
461 | |
462 double frexp(double value, int* exp); | |
463 float frexpf(float value, int* exp); | |
464 real frexpl(real value, int* exp); | |
465 | |
466 int ilogb(double x); | |
467 int ilogbf(float x); | |
468 int ilogbl(real x); | |
469 | |
470 double ldexp(double x, int exp); | |
471 float ldexpf(float x, int exp); | |
472 real ldexpl(real x, int exp); | |
473 | |
474 double log(double x); | |
475 float logf(float x); | |
476 real logl(real x); | |
477 | |
478 double log10(double x); | |
479 float log10f(float x); | |
480 real log10l(real x); | |
481 | |
482 double log1p(double x); | |
483 float log1pf(float x); | |
484 real log1pl(real x); | |
485 | |
486 double log2(double x); | |
487 float log2f(float x); | |
488 real log2l(real x); | |
489 | |
490 double logb(double x); | |
491 float logbf(float x); | |
492 real logbl(real x); | |
493 | |
494 double modf(double value, double* iptr); | |
495 float modff(float value, float* iptr); | |
496 real modfl(real value, real *iptr); | |
497 | |
498 double scalbn(double x, int n); | |
499 float scalbnf(float x, int n); | |
500 real scalbnl(real x, int n); | |
501 | |
502 double scalbln(double x, c_long n); | |
503 float scalblnf(float x, c_long n); | |
504 real scalblnl(real x, c_long n); | |
505 | |
506 double cbrt(double x); | |
507 float cbrtf(float x); | |
508 real cbrtl(real x); | |
509 | |
510 double fabs(double x); | |
511 float fabsf(float x); | |
512 real fabsl(real x); | |
513 | |
514 double hypot(double x, double y); | |
515 float hypotf(float x, float y); | |
516 real hypotl(real x, real y); | |
517 | |
518 double pow(double x, double y); | |
519 float powf(float x, float y); | |
520 real powl(real x, real y); | |
521 | |
522 double sqrt(double x); | |
523 float sqrtf(float x); | |
524 real sqrtl(real x); | |
525 | |
526 double erf(double x); | |
527 float erff(float x); | |
528 real erfl(real x); | |
529 | |
530 double erfc(double x); | |
531 float erfcf(float x); | |
532 real erfcl(real x); | |
533 | |
534 double lgamma(double x); | |
535 float lgammaf(float x); | |
536 real lgammal(real x); | |
537 | |
538 double tgamma(double x); | |
539 float tgammaf(float x); | |
540 real tgammal(real x); | |
541 | |
542 double ceil(double x); | |
543 float ceilf(float x); | |
544 real ceill(real x); | |
545 | |
546 double floor(double x); | |
547 float floorf(float x); | |
548 real floorl(real x); | |
549 | |
550 double nearbyint(double x); | |
551 float nearbyintf(float x); | |
552 real nearbyintl(real x); | |
553 | |
554 double rint(double x); | |
555 float rintf(float x); | |
556 real rintl(real x); | |
557 | |
558 c_long lrint(double x); | |
559 c_long lrintf(float x); | |
560 c_long lrintl(real x); | |
561 | |
562 long llrint(double x); | |
563 long llrintf(float x); | |
564 long llrintl(real x); | |
565 | |
566 double round(double x); | |
567 float roundf(float x); | |
568 real roundl(real x); | |
569 | |
570 c_long lround(double x); | |
571 c_long lroundf(float x); | |
572 c_long lroundl(real x); | |
573 | |
574 long llround(double x); | |
575 long llroundf(float x); | |
576 long llroundl(real x); | |
577 | |
578 double trunc(double x); | |
579 float truncf(float x); | |
580 real truncl(real x); | |
581 | |
582 double fmod(double x, double y); | |
583 float fmodf(float x, float y); | |
584 real fmodl(real x, real y); | |
585 | |
586 double remainder(double x, double y); | |
587 float remainderf(float x, float y); | |
588 real remainderl(real x, real y); | |
589 | |
590 double remquo(double x, double y, int* quo); | |
591 float remquof(float x, float y, int* quo); | |
592 real remquol(real x, real y, int* quo); | |
593 | |
594 double copysign(double x, double y); | |
595 float copysignf(float x, float y); | |
596 real copysignl(real x, real y); | |
597 | |
598 double nan(char* tagp); | |
599 float nanf(char* tagp); | |
600 real nanl(char* tagp); | |
601 | |
602 double nextafter(double x, double y); | |
603 float nextafterf(float x, float y); | |
604 real nextafterl(real x, real y); | |
605 | |
606 double nexttoward(double x, real y); | |
607 float nexttowardf(float x, real y); | |
608 real nexttowardl(real x, real y); | |
609 | |
610 double fdim(double x, double y); | |
611 float fdimf(float x, float y); | |
612 real fdiml(real x, real y); | |
613 | |
614 double fmax(double x, double y); | |
615 float fmaxf(float x, float y); | |
616 real fmaxl(real x, real y); | |
617 | |
618 double fmin(double x, double y); | |
619 float fminf(float x, float y); | |
620 real fminl(real x, real y); | |
621 | |
622 double fma(double x, double y, double z); | |
623 float fmaf(float x, float y, float z); | |
624 real fmal(real x, real y, real z); |