comparison lphobos/std/c/fenv.d @ 1:c53b6e3fe49a trunk

[svn r5] Initial commit. Most things are very rough.
author lindquist
date Sat, 01 Sep 2007 21:43:27 +0200
parents
children
comparison
equal deleted inserted replaced
0:a9e71648e74d 1:c53b6e3fe49a
1
2 /**
3 * C's <fenv.h>
4 * Authors: Walter Bright, Digital Mars, www.digitalmars.com
5 * License: Public Domain
6 * Macros:
7 * WIKI=Phobos/StdCFenv
8 */
9
10 module std.c.fenv;
11
12 extern (C):
13
14 /// Entire floating point environment
15
16 struct fenv_t
17 {
18 version (Windows)
19 {
20 ushort status;
21 ushort control;
22 ushort round;
23 ushort reserved[2];
24 }
25 else version (linux)
26 {
27 ushort __control_word;
28 ushort __unused1;
29 ushort __status_word;
30 ushort __unused2;
31 ushort __tags;
32 ushort __unused3;
33 uint __eip;
34 ushort __cs_selector;
35 ushort __opcode;
36 uint __data_offset;
37 ushort __data_selector;
38 ushort __unused5;
39 }
40 else
41 {
42 static assert(0);
43 }
44 }
45
46 alias int fexcept_t; /// Floating point status flags
47
48 /// The various floating point exceptions
49 enum
50 {
51 FE_INVALID = 1, ///
52 FE_DENORMAL = 2, ///
53 FE_DIVBYZERO = 4, ///
54 FE_OVERFLOW = 8, ///
55 FE_UNDERFLOW = 0x10, ///
56 FE_INEXACT = 0x20, ///
57 FE_ALL_EXCEPT = 0x3F, /// Mask of all the exceptions
58 }
59
60 /// Rounding modes
61 enum
62 {
63 FE_TONEAREST = 0, ///
64 FE_UPWARD = 0x800, ///
65 FE_DOWNWARD = 0x400, ///
66 FE_TOWARDZERO = 0xC00, ///
67 }
68
69 version (Windows)
70 {
71 extern fenv_t _FE_DFL_ENV;
72
73 /// Default floating point environment
74 fenv_t* FE_DFL_ENV = &_FE_DFL_ENV;
75 }
76 else version (linux)
77 {
78 /// Default floating point environment
79 fenv_t* FE_DFL_ENV = cast(fenv_t*)(-1);
80 }
81 else
82 {
83 static assert(0);
84 }
85
86 /// Floating point precision
87 enum
88 {
89 FE_FLTPREC = 0, ///
90 FE_DBLPREC = 0x200, ///
91 FE_LDBLPREC = 0x300, ///
92 }
93
94 int fetestexcept(int excepts); ///
95 int feraiseexcept(int excepts); ///
96 int feclearexcept(int excepts); ///
97 //int fegetexcept(fexcept_t *flagp,int excepts); ///
98 //int fesetexcept(fexcept_t *flagp,int excepts); ///
99 int fegetround(); ///
100 int fesetround(int round); ///
101 int fegetprec(); ///
102 int fesetprec(int prec); ///
103 int fegetenv(fenv_t *envp); ///
104 int fesetenv(fenv_t *envp); ///
105 //void feprocentry(fenv_t *envp); ///
106 //void feprocexit(const fenv_t *envp); ///
107
108 int fegetexceptflag(fexcept_t *flagp,int excepts); ///
109 int fesetexceptflag(fexcept_t *flagp,int excepts); ///
110 int feholdexcept(fenv_t *envp); ///
111 int feupdateenv(fenv_t *envp); ///
112