This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
fenv.d
236 lines (217 loc) · 4.98 KB
/
fenv.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
* D header file for C99.
*
* Copyright: Copyright Sean Kelly 2005 - 2009.
* License: Distributed under the
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
* (See accompanying file LICENSE)
* Authors: Sean Kelly
* Source: $(DRUNTIMESRC core/stdc/_fenv.d)
* Standards: ISO/IEC 9899:1999 (E)
*/
module core.stdc.fenv;
extern (C):
@system:
nothrow:
@nogc:
version( Windows )
{
struct fenv_t
{
ushort status;
ushort control;
ushort round;
ushort[2] reserved;
}
alias int fexcept_t;
}
else version( linux )
{
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86/fpu/bits/fenv.h
version (X86)
{
struct fenv_t
{
ushort __control_word;
ushort __unused1;
ushort __status_word;
ushort __unused2;
ushort __tags;
ushort __unused3;
uint __eip;
ushort __cs_selector;
ushort __opcode;
uint __data_offset;
ushort __data_selector;
ushort __unused5;
}
alias fexcept_t = ushort;
}
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86/fpu/bits/fenv.h
else version (X86_64)
{
struct fenv_t
{
ushort __control_word;
ushort __unused1;
ushort __status_word;
ushort __unused2;
ushort __tags;
ushort __unused3;
uint __eip;
ushort __cs_selector;
ushort __opcode;
uint __data_offset;
ushort __data_selector;
ushort __unused5;
uint __mxcsr;
}
alias fexcept_t = ushort;
}
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/mips/bits/fenv.h
else version (MIPS32)
{
struct fenv_t
{
uint __fp_control_register;
}
alias fexcept_t = ushort;
}
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/mips/bits/fenv.h
else version (MIPS64)
{
struct fenv_t
{
uint __fp_control_register;
}
alias fexcept_t = ushort;
}
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/bits/fenv.h
else version (ARM)
{
struct fenv_t
{
uint __cw;
}
alias fexcept_t = uint;
}
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/powerpc/bits/fenv.h
else version (PPC64)
{
alias fenv_t = double;
alias fexcept_t = uint;
}
else
{
static assert(0, "Unimplemented architecture");
}
}
else version ( OSX )
{
version ( BigEndian )
{
alias uint fenv_t;
alias uint fexcept_t;
}
version ( LittleEndian )
{
struct fenv_t
{
ushort __control;
ushort __status;
uint __mxcsr;
byte[8] __reserved;
}
alias ushort fexcept_t;
}
}
else version ( FreeBSD )
{
struct fenv_t
{
ushort __control;
ushort __mxcsr_hi;
ushort __status;
ushort __mxcsr_lo;
uint __tag;
byte[16] __other;
}
alias ushort fexcept_t;
}
else version( Android )
{
version(X86)
{
struct fenv_t
{
ushort __control;
ushort __mxcsr_hi;
ushort __status;
ushort __mxcsr_lo;
uint __tag;
byte[16] __other;
}
alias ushort fexcept_t;
}
else
{
static assert(false, "Architecture not supported.");
}
}
else
{
static assert( false, "Unsupported platform" );
}
enum
{
FE_INVALID = 1,
FE_DENORMAL = 2, // non-standard
FE_DIVBYZERO = 4,
FE_OVERFLOW = 8,
FE_UNDERFLOW = 0x10,
FE_INEXACT = 0x20,
FE_ALL_EXCEPT = 0x3F,
FE_TONEAREST = 0,
FE_UPWARD = 0x800,
FE_DOWNWARD = 0x400,
FE_TOWARDZERO = 0xC00,
}
version( Windows )
{
private extern __gshared fenv_t _FE_DFL_ENV;
fenv_t* FE_DFL_ENV = &_FE_DFL_ENV;
}
else version( linux )
{
fenv_t* FE_DFL_ENV = cast(fenv_t*)(-1);
}
else version( OSX )
{
private extern __gshared fenv_t _FE_DFL_ENV;
fenv_t* FE_DFL_ENV = &_FE_DFL_ENV;
}
else version( FreeBSD )
{
private extern const fenv_t __fe_dfl_env;
const fenv_t* FE_DFL_ENV = &__fe_dfl_env;
}
else version( Android )
{
private extern const fenv_t __fe_dfl_env;
const fenv_t* FE_DFL_ENV = &__fe_dfl_env;
}
else
{
static assert( false, "Unsupported platform" );
}
void feraiseexcept(int excepts);
void feclearexcept(int excepts);
int fetestexcept(int excepts);
int feholdexcept(fenv_t* envp);
void fegetexceptflag(fexcept_t* flagp, int excepts);
void fesetexceptflag(in fexcept_t* flagp, int excepts);
int fegetround();
int fesetround(int round);
void fegetenv(fenv_t* envp);
void fesetenv(in fenv_t* envp);
void feupdateenv(in fenv_t* envp);