Debian Codegraph @

libphobos/libdruntime/core/stdc/fenv.d

raw
1 /**
2 * D header file for C99.
3 *
4 * $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_fenv.h.html, _fenv.h)
5 *
6 * Copyright: Copyright Sean Kelly 2005 - 2009.
7 * License: Distributed under the
8 * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
9 * (See accompanying file LICENSE)
10 * Authors: Sean Kelly
11 * Source: $(DRUNTIMESRC core/stdc/_fenv.d)
12 * Standards: ISO/IEC 9899:1999 (E)
13 */
14
15 module core.stdc.fenv;
16
17 version (OSX)
18 version = Darwin;
19 else version (iOS)
20 version = Darwin;
21 else version (TVOS)
22 version = Darwin;
23 else version (WatchOS)
24 version = Darwin;
25
26 extern (C):
27 nothrow:
28 @nogc:
29
30 version (ARM) version = ARM_Any;
31 version (AArch64) version = ARM_Any;
32 version (HPPA) version = HPPA_Any;
33 version (MIPS32) version = MIPS_Any;
34 version (MIPS64) version = MIPS_Any;
35 version (PPC) version = PPC_Any;
36 version (PPC64) version = PPC_Any;
37 version (RISCV32) version = RISCV_Any;
38 version (RISCV64) version = RISCV_Any;
39 version (S390) version = IBMZ_Any;
40 version (SPARC) version = SPARC_Any;
41 version (SPARC64) version = SPARC_Any;
42 version (SystemZ) version = IBMZ_Any;
43 version (X86) version = X86_Any;
44 version (X86_64) version = X86_Any;
45
46 version (MinGW)
47 version = GNUFP;
48 version (CRuntime_Glibc)
49 version = GNUFP;
50
51 version (GNUFP)
52 {
53 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86/fpu/bits/fenv.h
54 version (X86)
55 {
56 struct fenv_t
57 {
58 ushort __control_word;
59 ushort __unused1;
60 ushort __status_word;
61 ushort __unused2;
62 ushort __tags;
63 ushort __unused3;
64 uint __eip;
65 ushort __cs_selector;
66 ushort __opcode;
67 uint __data_offset;
68 ushort __data_selector;
69 ushort __unused5;
70 }
71
72 alias fexcept_t = ushort;
73 }
74 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86/fpu/bits/fenv.h
75 else version (X86_64)
76 {
77 struct fenv_t
78 {
79 ushort __control_word;
80 ushort __unused1;
81 ushort __status_word;
82 ushort __unused2;
83 ushort __tags;
84 ushort __unused3;
85 uint __eip;
86 ushort __cs_selector;
87 ushort __opcode;
88 uint __data_offset;
89 ushort __data_selector;
90 ushort __unused5;
91 uint __mxcsr;
92 }
93
94 alias fexcept_t = ushort;
95 }
96 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/hppa/bits/fenv.h
97 else version (HPPA_Any)
98 {
99 struct fenv_t
100 {
101 uint __status_word;
102 uint[7] __exception;
103 }
104
105 alias fexcept_t = uint;
106 }
107 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/mips/bits/fenv.h
108 else version (MIPS_Any)
109 {
110 struct fenv_t
111 {
112 uint __fp_control_register;
113 }
114
115 alias fexcept_t = ushort;
116 }
117 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/aarch64/bits/fenv.h
118 else version (AArch64)
119 {
120 struct fenv_t
121 {
122 uint __fpcr;
123 uint __fpsr;
124 }
125
126 alias fexcept_t = uint;
127 }
128 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/bits/fenv.h
129 else version (ARM)
130 {
131 struct fenv_t
132 {
133 uint __cw;
134 }
135
136 alias fexcept_t = uint;
137 }
138 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/powerpc/bits/fenv.h
139 else version (PPC_Any)
140 {
141 alias fenv_t = double;
142 alias fexcept_t = uint;
143 }
144 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/riscv/bits/fenv.h
145 else version (RISCV_Any)
146 {
147 alias fenv_t = uint;
148 alias fexcept_t = uint;
149 }
150 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/sparc/fpu/bits/fenv.h
151 else version (SPARC_Any)
152 {
153 import core.stdc.config : c_ulong;
154
155 alias fenv_t = c_ulong;
156 alias fexcept_t = c_ulong;
157 }
158 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/s390/fpu/bits/fenv.h
159 else version (IBMZ_Any)
160 {
161 struct fenv_t
162 {
163 fexcept_t __fpc;
164 void* __unused;
165 }
166
167 alias fexcept_t = uint;
168 }
169 else version (LoongArch64)
170 {
171 struct fenv_t
172 {
173 uint __fp_control_register;
174 }
175
176 alias fexcept_t = uint;
177 }
178 else
179 {
180 static assert(0, "Unimplemented architecture");
181 }
182 }
183 else version (CRuntime_Microsoft)
184 {
185 struct fenv_t
186 {
187 uint ctl;
188 uint stat;
189 }
190
191 alias fexcept_t = uint;
192 }
193 else version (Darwin)
194 {
195 version (BigEndian)
196 {
197 alias uint fenv_t;
198 alias uint fexcept_t;
199 }
200 version (LittleEndian)
201 {
202 struct fenv_t
203 {
204 ushort __control;
205 ushort __status;
206 uint __mxcsr;
207 byte[8] __reserved;
208 }
209
210 alias ushort fexcept_t;
211 }
212 }
213 else version (FreeBSD)
214 {
215 struct fenv_t
216 {
217 ushort __control;
218 ushort __mxcsr_hi;
219 ushort __status;
220 ushort __mxcsr_lo;
221 uint __tag;
222 byte[16] __other;
223 }
224
225 alias ushort fexcept_t;
226 }
227 else version (NetBSD)
228 {
229 version (X86_64)
230 {
231 struct fenv_t
232 {
233 struct _x87
234 {
235 uint control; /* Control word register */
236 uint status; /* Status word register */
237 uint tag; /* Tag word register */
238 uint[4] others; /* EIP, Pointer Selector, etc */
239 }
240 _x87 x87;
241
242 uint mxcsr; /* Control and status register */
243 }
244 }
245 version (X86)
246 {
247 struct fenv_t
248 {
249 struct _x87
250 {
251 ushort control; /* Control word register */
252 ushort unused1;
253 ushort status; /* Status word register */
254 ushort unused2;
255 ushort tag; /* Tag word register */
256 ushort unused3;
257 uint[4] others; /* EIP, Pointer Selector, etc */
258 }
259 _x87 x87;
260 uint mxcsr; /* Control and status register */
261 }
262
263 }
264
265 alias uint fexcept_t;
266 }
267 else version (OpenBSD)
268 {
269 struct fenv_t
270 {
271 struct __x87
272 {
273 uint __control;
274 uint __status;
275 uint __tag;
276 uint[4] __others;
277 }
278 }
279 uint __mxcsr;
280
281 alias fexcept_t = uint;
282 }
283 else version (DragonFlyBSD)
284 {
285 struct fenv_t
286 {
287 struct _x87
288 {
289 uint control;
290 uint status;
291 uint tag;
292 uint[4] others;
293 }
294 _x87 x87;
295
296 uint mxcsr;
297 }
298
299 alias uint fexcept_t;
300 }
301 else version (CRuntime_Bionic)
302 {
303 version (X86)
304 {
305 struct fenv_t
306 {
307 ushort __control;
308 ushort __mxcsr_hi;
309 ushort __status;
310 ushort __mxcsr_lo;
311 uint __tag;
312 byte[16] __other;
313 }
314
315 alias ushort fexcept_t;
316 }
317 else version (ARM)
318 {
319 alias uint fenv_t;
320 alias uint fexcept_t;
321 }
322 else version (AArch64)
323 {
324 struct fenv_t
325 {
326 uint __control;
327 uint __status;
328 }
329
330 alias uint fexcept_t;
331 }
332 else version (X86_64)
333 {
334 struct fenv_t
335 {
336 struct _x87
337 {
338 uint __control;
339 uint __status;
340 uint __tag;
341 uint[4] __others;
342 }
343 _x87 __x87;
344
345 uint __mxcsr;
346 }
347
348 alias uint fexcept_t;
349 }
350 else
351 {
352 static assert(false, "Architecture not supported.");
353 }
354 }
355 else version (Solaris)
356 {
357 import core.stdc.config : c_ulong;
358
359 enum FEX_NUM_EXC = 12;
360
361 struct fex_handler_t
362 {
363 int __mode;
364 void function() __handler;
365 }
366
367 struct fenv_t
368 {
369 fex_handler_t[FEX_NUM_EXC] __handler;
370 c_ulong __fsr;
371 }
372
373 alias int fexcept_t;
374 }
375 else version (CRuntime_Musl)
376 {
377 version (AArch64)
378 {
379 struct fenv_t
380 {
381 uint __fpcr;
382 uint __fpsr;
383 }
384 alias uint fexcept_t;
385 }
386 else version (ARM)
387 {
388 import core.stdc.config : c_ulong;
389
390 struct fenv_t
391 {
392 c_ulong __cw;
393 }
394 alias c_ulong fexcept_t;
395 }
396 else version (IBMZ_Any)
397 {
398 alias uint fenv_t;
399 alias uint fexcept_t;
400 }
401 else version (MIPS_Any)
402 {
403 struct fenv_t
404 {
405 uint __cw;
406 }
407 alias ushort fexcept_t;
408 }
409 else version (PPC_Any)
410 {
411 alias double fenv_t;
412 alias uint fexcept_t;
413 }
414 else version (X86_Any)
415 {
416 struct fenv_t
417 {
418 ushort __control_word;
419 ushort __unused1;
420 ushort __status_word;
421 ushort __unused2;
422 ushort __tags;
423 ushort __unused3;
424 uint __eip;
425 ushort __cs_selector;
426 ushort __opcode;
427 uint __data_offset;
428 ushort __data_selector;
429 ushort __unused5;
430 version (X86_64)
431 uint __mxcsr;
432 }
433 alias ushort fexcept_t;
434 }
435 else version (LoongArch64)
436 {
437 struct fenv_t
438 {
439 uint __cw;
440 }
441 alias uint fexcept_t;
442 }
443 else
444 {
445 static assert(false, "Architecture not supported.");
446 }
447 }
448 else version (CRuntime_Newlib)
449 {
450 version (AArch64)
451 {
452 alias fenv_t = ulong;
453 alias fexcept_t = ulong;
454 }
455 else version (RISCV_Any)
456 {
457 alias fenv_t = size_t;
458 alias fexcept_t = size_t;
459 }
460 else version (X86_Any)
461 {
462 struct fenv_t
463 {
464 uint _fpu_cw;
465 uint _fpu_sw;
466 uint _fpu_tagw;
467 uint _fpu_ipoff;
468 uint _fpu_ipsel;
469 uint _fpu_opoff;
470 uint _fpu_opsel;
471 uint _sse_mxcsr;
472 }
473 alias fexcept_t = uint;
474 }
475 else version (SPARC64)
476 {
477 alias fenv_t = ulong;
478 alias fexcept_t = ulong;
479 }
480 else version (SPARC)
481 {
482 alias fenv_t = uint;
483 alias fexcept_t = uint;
484 }
485 else
486 {
487 alias fenv_t = int;
488 alias fexcept_t = int;
489 }
490 }
491 else version (CRuntime_UClibc)
492 {
493 version (X86)
494 {
495 struct fenv_t
496 {
497 ushort __control_word;
498 ushort __unused1;
499 ushort __status_word;
500 ushort __unused2;
501 ushort __tags;
502 ushort __unused3;
503 uint __eip;
504 ushort __cs_selector;
505 ushort __opcode;
506 uint __data_offset;
507 ushort __data_selector;
508 ushort __unused5;
509 }
510
511 alias fexcept_t = ushort;
512 }
513 else version (X86_64)
514 {
515 struct fenv_t
516 {
517 ushort __control_word;
518 ushort __unused1;
519 ushort __status_word;
520 ushort __unused2;
521 ushort __tags;
522 ushort __unused3;
523 uint __eip;
524 ushort __cs_selector;
525 ushort __opcode;
526 uint __data_offset;
527 ushort __data_selector;
528 ushort __unused5;
529 uint __mxcsr;
530 }
531
532 alias fexcept_t = ushort;
533 }
534 else version (MIPS_Any)
535 {
536 struct fenv_t
537 {
538 uint __fp_control_register;
539 }
540
541 alias fexcept_t = ushort;
542 }
543 else version (ARM)
544 {
545 struct fenv_t
546 {
547 uint __cw;
548 }
549
550 alias fexcept_t = uint;
551 }
552 else
553 {
554 static assert(false, "Architecture not supported.");
555 }
556 }
557 else
558 {
559 static assert( false, "Unsupported platform" );
560 }
561
562 version (CRuntime_Microsoft)
563 {
564 enum
565 {
566 FE_INEXACT = 1, ///
567 FE_UNDERFLOW = 2, ///
568 FE_OVERFLOW = 4, ///
569 FE_DIVBYZERO = 8, ///
570 FE_INVALID = 0x10, ///
571 FE_ALL_EXCEPT = 0x1F, ///
572 FE_TONEAREST = 0, ///
573 FE_UPWARD = 0x100, ///
574 FE_DOWNWARD = 0x200, ///
575 FE_TOWARDZERO = 0x300, ///
576 }
577 }
578 else version (Solaris)
579 {
580 version (SPARC_Any)
581 {
582 enum
583 {
584 FE_TONEAREST = 0,
585 FE_TOWARDZERO = 1,
586 FE_UPWARD = 2,
587 FE_DOWNWARD = 3,
588 }
589
590 enum
591 {
592 FE_INEXACT = 0x01,
593 FE_DIVBYZERO = 0x02,
594 FE_UNDERFLOW = 0x04,
595 FE_OVERFLOW = 0x08,
596 FE_INVALID = 0x10,
597 FE_ALL_EXCEPT = 0x1f,
598 }
599
600 }
601 else version (X86_Any)
602 {
603 enum
604 {
605 FE_TONEAREST = 0,
606 FE_DOWNWARD = 1,
607 FE_UPWARD = 2,
608 FE_TOWARDZERO = 3,
609 }
610
611 enum
612 {
613 FE_INVALID = 0x01,
614 FE_DIVBYZERO = 0x04,
615 FE_OVERFLOW = 0x08,
616 FE_UNDERFLOW = 0x10,
617 FE_INEXACT = 0x20,
618 FE_ALL_EXCEPT = 0x3d,
619 }
620 }
621 else
622 {
623 static assert(0, "Unimplemented architecture");
624 }
625 }
626 else
627 {
628 version (X86)
629 {
630 // Define bits representing the exception.
631 enum
632 {
633 FE_INVALID = 0x01, ///
634 FE_DENORMAL = 0x02, /// non-standard
635 FE_DIVBYZERO = 0x04, ///
636 FE_OVERFLOW = 0x08, ///
637 FE_UNDERFLOW = 0x10, ///
638 FE_INEXACT = 0x20, ///
639 FE_ALL_EXCEPT = 0x3F, ///
640 }
641
642 // The ix87 FPU supports all of the four defined rounding modes.
643 enum
644 {
645 FE_TONEAREST = 0, ///
646 FE_DOWNWARD = 0x400, ///
647 FE_UPWARD = 0x800, ///
648 FE_TOWARDZERO = 0xC00, ///
649 }
650 }
651 else version (X86_64)
652 {
653 // Define bits representing the exception.
654 enum
655 {
656 FE_INVALID = 0x01, ///
657 FE_DENORMAL = 0x02, /// non-standard
658 FE_DIVBYZERO = 0x04, ///
659 FE_OVERFLOW = 0x08, ///
660 FE_UNDERFLOW = 0x10, ///
661 FE_INEXACT = 0x20, ///
662 FE_ALL_EXCEPT = 0x3F, ///
663 }
664
665 // The ix87 FPU supports all of the four defined rounding modes.
666 enum
667 {
668 FE_TONEAREST = 0, ///
669 FE_DOWNWARD = 0x400, ///
670 FE_UPWARD = 0x800, ///
671 FE_TOWARDZERO = 0xC00, ///
672 }
673 }
674 else version (ARM_Any)
675 {
676 // Define bits representing exceptions in the FPU status word.
677 enum
678 {
679 FE_INVALID = 1, ///
680 FE_DIVBYZERO = 2, ///
681 FE_OVERFLOW = 4, ///
682 FE_UNDERFLOW = 8, ///
683 FE_INEXACT = 16, ///
684 FE_ALL_EXCEPT = 31, ///
685 }
686
687 // VFP supports all of the four defined rounding modes.
688 enum
689 {
690 FE_TONEAREST = 0, ///
691 FE_UPWARD = 0x400000, ///
692 FE_DOWNWARD = 0x800000, ///
693 FE_TOWARDZERO = 0xC00000, ///
694 }
695 }
696 else version (HPPA_Any)
697 {
698 // Define bits representing the exception.
699 enum
700 {
701 FE_INEXACT = 0x01, ///
702 FE_UNDERFLOW = 0x02, ///
703 FE_OVERFLOW = 0x04, ///
704 FE_DIVBYZERO = 0x08, ///
705 FE_INVALID = 0x10, ///
706 FE_ALL_EXCEPT = 0x1F, ///
707 }
708
709 // The HPPA FPU supports all of the four defined rounding modes.
710 enum
711 {
712 FE_TONEAREST = 0x0, ///
713 FE_TOWARDZERO = 0x200, ///
714 FE_UPWARD = 0x400, ///
715 FE_DOWNWARD = 0x600, ///
716 }
717 }
718 else version (MIPS_Any)
719 {
720 // Define bits representing the exception.
721 enum
722 {
723 FE_INEXACT = 0x04, ///
724 FE_UNDERFLOW = 0x08, ///
725 FE_OVERFLOW = 0x10, ///
726 FE_DIVBYZERO = 0x20, ///
727 FE_INVALID = 0x40, ///
728 FE_ALL_EXCEPT = 0x7C, ///
729 }
730
731 // The MIPS FPU supports all of the four defined rounding modes.
732 enum
733 {
734 FE_TONEAREST = 0x0, ///
735 FE_TOWARDZERO = 0x1, ///
736 FE_UPWARD = 0x2, ///
737 FE_DOWNWARD = 0x3, ///
738 }
739 }
740 else version (PPC_Any)
741 {
742 // Define bits representing the exception.
743 enum
744 {
745 FE_INEXACT = 0x2000000, ///
746 FE_DIVBYZERO = 0x4000000, ///
747 FE_UNDERFLOW = 0x8000000, ///
748 FE_OVERFLOW = 0x10000000, ///
749 FE_INVALID = 0x20000000, ///
750 FE_INVALID_SNAN = 0x1000000, /// non-standard
751 FE_INVALID_ISI = 0x800000, /// non-standard
752 FE_INVALID_IDI = 0x400000, /// non-standard
753 FE_INVALID_ZDZ = 0x200000, /// non-standard
754 FE_INVALID_IMZ = 0x100000, /// non-standard
755 FE_INVALID_COMPARE = 0x80000, /// non-standard
756 FE_INVALID_SOFTWARE = 0x400, /// non-standard
757 FE_INVALID_SQRT = 0x200, /// non-standard
758 FE_INVALID_INTEGER_CONVERSION = 0x100, /// non-standard
759 FE_ALL_INVALID = 0x1F80700, /// non-standard
760 FE_ALL_EXCEPT = 0x3E000000, ///
761 }
762
763 // PowerPC chips support all of the four defined rounding modes.
764 enum
765 {
766 FE_TONEAREST = 0, ///
767 FE_TOWARDZERO = 1, ///
768 FE_UPWARD = 2, ///
769 FE_DOWNWARD = 3, ///
770 }
771 }
772 else version (RISCV_Any)
773 {
774 // Define bits representing exceptions in the FPSR status word.
775 enum
776 {
777 FE_INEXACT = 0x01, ///
778 FE_UNDERFLOW = 0x02, ///
779 FE_OVERFLOW = 0x04, ///
780 FE_DIVBYZERO = 0x08, ///
781 FE_INVALID = 0x10, ///
782 FE_ALL_EXCEPT = 0x1f, ///
783 }
784
785 // Define bits representing rounding modes in the FPCR Rmode field.
786 enum
787 {
788 FE_TONEAREST = 0x0, ///
789 FE_TOWARDZERO = 0x1, ///
790 FE_DOWNWARD = 0x2, ///
791 FE_UPWARD = 0x3, ///
792 }
793 }
794 else version (SPARC_Any)
795 {
796 // Define bits representing the exception.
797 enum
798 {
799 FE_INVALID = 0x200, ///
800 FE_OVERFLOW = 0x100, ///
801 FE_UNDERFLOW = 0x80, ///
802 FE_DIVBYZERO = 0x40, ///
803 FE_INEXACT = 0x20, ///
804 FE_ALL_EXCEPT = 0x3E0, ///
805 }
806
807 // The Sparc FPU supports all of the four defined rounding modes.
808 enum
809 {
810 FE_TONEAREST = 0x0, ///
811 FE_TOWARDZERO = 0x40000000, ///
812 FE_UPWARD = 0x80000000, ///
813 FE_DOWNWARD = 0xc0000000, ///
814 }
815 }
816 else version (IBMZ_Any)
817 {
818 // Define bits representing the exception.
819 enum
820 {
821 FE_INVALID = 0x80, ///
822 FE_DIVBYZERO = 0x40, ///
823 FE_OVERFLOW = 0x20, ///
824 FE_UNDERFLOW = 0x10, ///
825 FE_INEXACT = 0x08, ///
826 FE_ALL_EXCEPT = 0xF8, ///
827 }
828
829 // SystemZ supports all of the four defined rounding modes.
830 enum
831 {
832 FE_TONEAREST = 0x0, ///
833 FE_DOWNWARD = 0x3, ///
834 FE_UPWARD = 0x2, ///
835 FE_TOWARDZERO = 0x1, ///
836 }
837 }
838 else version (LoongArch64)
839 {
840 // Define bits representing exceptions in the Flags field in FCSR{0,2}.
841 enum
842 {
843 FE_INEXACT = 0x010000, ///
844 FE_UNDERFLOW = 0x020000, ///
845 FE_OVERFLOW = 0x040000, ///
846 FE_DIVBYZERO = 0x080000, ///
847 FE_INVALID = 0x100000, ///
848 FE_ALL_EXCEPT = 0x1f0000, ///
849 }
850
851 // Define bits representing rounding modes in the RM field in FCSR{0,3}.
852 enum
853 {
854 FE_TONEAREST = 0x000, ///
855 FE_TOWARDZERO = 0x100, ///
856 FE_UPWARD = 0x200, ///
857 FE_DOWNWARD = 0x300, ///
858 }
859 }
860 else
861 {
862 static assert(0, "Unimplemented architecture");
863 }
864
865 }
866
867 version (GNUFP)
868 {
869 ///
870 enum FE_DFL_ENV = cast(fenv_t*)(-1);
871 }
872 else version (CRuntime_Microsoft)
873 {
874 private extern __gshared fenv_t _Fenv0;
875 ///
876 enum FE_DFL_ENV = &_Fenv0;
877 }
878 else version (Darwin)
879 {
880 private extern __gshared fenv_t _FE_DFL_ENV;
881 ///
882 enum FE_DFL_ENV = &_FE_DFL_ENV;
883 }
884 else version (FreeBSD)
885 {
886 private extern const fenv_t __fe_dfl_env;
887 ///
888 enum FE_DFL_ENV = &__fe_dfl_env;
889 }
890 else version (NetBSD)
891 {
892 private extern const fenv_t __fe_dfl_env;
893 ///
894 enum FE_DFL_ENV = &__fe_dfl_env;
895 }
896 else version (OpenBSD)
897 {
898 private extern const fenv_t __fe_dfl_env;
899 ///
900 enum FE_DFL_ENV = &__fe_dfl_env;
901 }
902 else version (DragonFlyBSD)
903 {
904 private extern const fenv_t __fe_dfl_env;
905 ///
906 enum FE_DFL_ENV = &__fe_dfl_env;
907 }
908 else version (CRuntime_Bionic)
909 {
910 private extern const fenv_t __fe_dfl_env;
911 ///
912 enum FE_DFL_ENV = &__fe_dfl_env;
913 }
914 else version (Solaris)
915 {
916 private extern const fenv_t __fenv_def_env;
917 ///
918 enum FE_DFL_ENV = &__fenv_def_env;
919 }
920 else version (CRuntime_Musl)
921 {
922 ///
923 enum FE_DFL_ENV = cast(fenv_t*)(-1);
924 }
925 else version (CRuntime_UClibc)
926 {
927 ///
928 enum FE_DFL_ENV = cast(fenv_t*)(-1);
929 }
930 else
931 {
932 static assert( false, "Unsupported platform" );
933 }
934
935 ///
936 int feclearexcept(int excepts);
937
938 ///
939 int fetestexcept(int excepts);
940 ///
941 int feholdexcept(fenv_t* envp);
942
943 ///
944 int fegetexceptflag(fexcept_t* flagp, int excepts);
945 ///
946 int fesetexceptflag(const scope fexcept_t* flagp, int excepts);
947
948 ///
949 int fegetround();
950 ///
951 int fesetround(int round);
952
953 ///
954 int fegetenv(fenv_t* envp);
955 ///
956 int fesetenv(const scope fenv_t* envp);
957
958 // MS define feraiseexcept() and feupdateenv() inline.
959 version (CRuntime_Microsoft) // supported since MSVCRT 12 (VS 2013) only
960 {
961 ///
962 int feraiseexcept()(int excepts)
963 {
964 struct Entry
965 {
966 int exceptVal;
967 double num;
968 double denom;
969 }
970 static immutable Entry[5] table =
971 [ // Raise exception by evaluating num / denom:
972 { FE_INVALID, 0.0, 0.0 },
973 { FE_DIVBYZERO, 1.0, 0.0 },
974 { FE_OVERFLOW, 1e+300, 1e-300 },
975 { FE_UNDERFLOW, 1e-300, 1e+300 },
976 { FE_INEXACT, 2.0, 3.0 }
977 ];
978
979 if ((excepts &= FE_ALL_EXCEPT) == 0)
980 return 0;
981
982 // Raise the exceptions not masked:
983 double ans = void;
984 foreach (i; 0 .. table.length)
985 {
986 if ((excepts & table[i].exceptVal) != 0)
987 ans = table[i].num / table[i].denom;
988 }
989
990 return 0;
991 }
992
993 ///
994 int feupdateenv()(const scope fenv_t* envp)
995 {
996 int excepts = fetestexcept(FE_ALL_EXCEPT);
997 return (fesetenv(envp) != 0 || feraiseexcept(excepts) != 0 ? 1 : 0);
998 }
999 }
1000 else
1001 {
1002 ///
1003 int feraiseexcept(int excepts);
1004 ///
1005 int feupdateenv(const scope fenv_t* envp);
1006 }