The OpenD Programming Language

DecimalView

Alias This

lightConst

ditto

Members

Functions

fromStringImpl
bool fromStringImpl(const(C)[] str, DecimalExponentKey key, int exponentShift)
lightConst
DecimalView!(const W) lightConst()
opCast
T opCast()

Mir parsing supports up-to quadruple precision. The conversion error is 0 ULP for normal numbers. Subnormal numbers with an exponent greater than or equal to -512 have upper error bound equal to 1 ULP.

signedCoefficient
BigIntView!W signedCoefficient()

Variables

coefficient
BigUIntView!W coefficient;
exponent
long exponent;
sign
bool sign;

Examples

{
    auto view = DecimalView!ulong(false, -8, BigUIntView!ulong.fromHexString("BEBC2000000011E1A3"));
    auto coeff = (cast(BigUIntView!uint)view.coefficient).lightConst;
    assert (algoM!double(0.0, coeff, cast(int)view.exponent) == 3.518437208883201171875E+013);
}

// TBD: triggers underflow
// {
//     auto view = DecimalView!ulong(false, 0, BigUIntView!ulong.fromHexString("88BF4748507FB9900ADB624CCFF8D78897DC900FB0460327D4D86D327219"));
//     auto coeff = (cast(BigUIntView!uint)view.coefficient).lightConst;
//     debug {
//         import std.stdio;
//         writefln("%s", algoM!float(0.0, coeff, cast(int)view.exponent));
//         writefln("%s", algoM!double(0.0, coeff, cast(int)view.exponent));
//     }
//     assert (algoM!float(0.0, coeff, cast(int)view.exponent) == float.infinity);
//     assert (algoM!double(0.0, coeff, cast(int)view.exponent) == 0x1.117e8e90a0ff7p+239);
// }

{
    auto view = DecimalView!ulong(false, -324, BigUIntView!ulong.fromHexString("4F0CEDC95A718E"));
    auto coeff = (cast(BigUIntView!uint)view.coefficient).lightConst;
    assert (algoM!float(0.0, coeff, cast(int)view.exponent) == 0);
    assert (algoM!double(0.0, coeff, cast(int)view.exponent) == 2.2250738585072014e-308);
}
1 import mir.test;
2 
3 auto view = DecimalView!size_t(false, -8, BigUIntView!size_t.fromHexString("BEBC2000000011E1A3"));
4 
5 should(cast(float)view) == 3.518437208883201171875E+013f;
6 should(cast(double)view) == 3.518437208883201171875E+013;
7 static if (real.mant_dig >= 64)
8     should(cast(real)view) == 3.518437208883201171875E+013L;
9 
10 view = DecimalView!size_t(true, -169, BigUIntView!size_t.fromHexString("5A174AEDA65CC"));
11 should(cast(float)view) == -0;
12 should(cast(double)view) == -0x1.1p-511;
13 static if (real.mant_dig >= 64)
14     should(cast(real)view) == -0x8.80000000000019fp-514L;
15 
16 view = DecimalView!size_t(true, 293, BigUIntView!size_t.fromHexString("36496F6C4ED38"));
17 should(cast(float)view) == -float.infinity;
18 should(cast(double)view) == -9.55024478104888e+307;
19 static if (real.mant_dig >= 64)
20     should(cast(real)view) == -9.55024478104888e+307L;
21 
22 view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("1"));
23 should(cast(float)view) == 1;
24 should(cast(double)view) == 1;
25 static if (real.mant_dig >= 64)
26     should(cast(real)view) == 1L;
27 
28 view = DecimalView!size_t(false, -5, BigUIntView!size_t.fromHexString("3"));
29 should(cast(float)view) == 3e-5f;
30 should(cast(double)view) == 3e-5;
31 static if (real.mant_dig >= 64)
32     should(cast(real)view) == 3e-5L;
33 
34 view = DecimalView!size_t(false, -1, BigUIntView!size_t.fromHexString("1"));
35 should(cast(float)view) == 0.1f;
36 should(cast(double)view) == 0.1;
37 static if (real.mant_dig >= 64)
38     should(cast(real)view) == 0.1L;
39 
40 view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("3039"));
41 should(cast(float)view) == 12345.0f;
42 should(cast(double)view) == 12345.0;
43 static if (real.mant_dig >= 64)
44     should(cast(real)view) == 12345.0L;
45 
46 view = DecimalView!size_t(false, -7, BigUIntView!size_t.fromHexString("98967F"));
47 should(cast(float)view) == 0.9999999f;
48 should(cast(double)view) == 0.9999999;
49 static if (real.mant_dig >= 64)
50     should(cast(real)view) == 0.9999999L;
51 
52 view = DecimalView!size_t(false, -324, BigUIntView!size_t.fromHexString("4F0CEDC95A718E"));
53 should(cast(float)view) == 0;
54 should(cast(double)view) == 2.2250738585072014e-308;
55 static if (real.mant_dig >= 64)
56     should(cast(real)view) == 2.2250738585072014e-308L;
57 
58 view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("1FFFFFFFFFFFFFFFD"));
59 should(cast(float)view) == 36893488147419103229f;
60 should(cast(double)view) == 36893488147419103229.0;
61 static if (real.mant_dig >= 64)
62     should(cast(real)view) == 0x1FFFFFFFFFFFFFFFDp0L;
63 
64 view = DecimalView!size_t(false, -33, BigUIntView!size_t.fromHexString("65"));
65 should(cast(float)view) == 101e-33f;
66 should(cast(double)view) == 101e-33;
67 static if (real.mant_dig >= 64)
68     should(cast(real)view) == 101e-33L;
69 
70 view = DecimalView!size_t(false, 23, BigUIntView!size_t.fromHexString("1"));
71 should(cast(float)view) == 1e23f;
72 should(cast(double)view) == 1e23;
73 static if (real.mant_dig >= 64)
74     should(cast(real)view) == 1e23L;
75 
76 view = DecimalView!size_t(false, 23, BigUIntView!size_t.fromHexString("81B"));
77 should(cast(float)view) == 2075e23f;
78 should(cast(double)view) == 0xaba3d58a1f1a98p+32;
79 static if (real.mant_dig >= 64)
80     should(cast(real)view) == 0xaba3d58a1f1a9cp+32L;
81 
82 view = DecimalView!size_t(false, -23, BigUIntView!size_t.fromHexString("2209"));
83 should(cast(float)view) == 8713e-23f;
84 should(cast(double)view) == 0x1.9b75b4e7de2b9p-64;
85 static if (real.mant_dig >= 64)
86     should(cast(real)view) == 0xc.dbada73ef15c401p-67L;
87 
88 view = DecimalView!size_t(false, 300, BigUIntView!size_t.fromHexString("1"));
89 should(cast(float)view) == float.infinity;
90 should(cast(double)view) == 0x1.7e43c8800759cp+996;
91 static if (real.mant_dig >= 64)
92     should(cast(real)view) == 0xb.f21e44003acdd2dp+993L;
93 
94 view = DecimalView!size_t(false, 245, BigUIntView!size_t.fromHexString("B3A73CEB227"));
95 should(cast(float)view) == float.infinity;
96 should(cast(double)view) == 0x1.48e3735333cb6p+857;
97 static if (real.mant_dig >= 64)
98     should(cast(real)view) == 0xa.471b9a999e5b01ep+854L;
99 
100 view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("88BF4748507FB9900ADB624CCFF8D78897DC900FB0460327D4D86D327219"));
101 should(cast(float)view) == float.infinity;
102 should(cast(double)view) == 0x1.117e8e90a0ff7p+239;
103 static if (real.mant_dig >= 64)
104     should(cast(real)view) == 0x8.8bf4748507fb99p+236L;
105 
106 view = DecimalView!size_t(false, -324, BigUIntView!size_t.fromHexString("5"));
107 should(cast(float)view) == 0;
108 should(cast(double)view) == 0x0.0000000000001p-1022;
109 static if (real.mant_dig >= 64)
110     should(cast(real)view) == 0x8.18995ce7aa0e1b2p-1077L;
111 
112 view = DecimalView!size_t(false, -324, BigUIntView!size_t.fromHexString("5B"));
113 should(cast(float)view) == 0;
114 should(cast(double)view) == 0x0.0000000000012p-1022;
115 static if (real.mant_dig >= 64)
116     should(cast(real)view) == 0x9.3594d9adeb09a55p-1073L;
117 
118 view = DecimalView!size_t(false, -322, BigUIntView!size_t.fromHexString("1"));
119 should(cast(float)view) == 0;
120 should(cast(double)view) == 0x0.0000000000014p-1022;
121 static if (real.mant_dig >= 64)
122     should(cast(real)view) == 0xa.1ebfb4219491a1fp-1073L;
123 
124 view = DecimalView!size_t(false, -320, BigUIntView!size_t.fromHexString("CA1CCB"));
125 should(cast(float)view) == 0;
126 should(cast(double)view) == 0x0.000063df832d9p-1022;
127 static if (real.mant_dig >= 64)
128     should(cast(real)view) == 0xc.7bf065b215888c7p-1043L;
129 
130 view = DecimalView!size_t(false, -319, BigUIntView!size_t.fromHexString("33CE7943FB"));
131 should(cast(float)view) == 0;
132 should(cast(double)view) == 0x1.000000000162p-1022;
133 static if (real.mant_dig >= 64)
134     should(cast(real)view) == 0x8.000000000b103b6p-1025L;
135 
136 view = DecimalView!size_t(false, -309, BigUIntView!size_t.fromHexString("15"));
137 should(cast(float)view) == 0;
138 should(cast(double)view) == 0x0.f19c2629ccf53p-1022;
139 static if (real.mant_dig >= 64)
140     should(cast(real)view) == 0xf.19c2629ccf52fc4p-1026L;
141 
142 view = DecimalView!size_t(false, -340, BigUIntView!size_t.fromHexString("AF87023B9BF0EE"));
143 should(cast(float)view) == 0;
144 should(cast(double)view) == 0x0.0000000000001p-1022;
145 static if (real.mant_dig >= 64)
146     should(cast(real)view) == 0xf.fffffffffffff64p-1078L;
147 
148 view = DecimalView!size_t(false, 400, BigUIntView!size_t.fromHexString("1"));
149 should(cast(float)view) == float.infinity;
150 should(cast(double)view) == double.infinity;
151 static if (real.mant_dig >= 64)
152     should(cast(real)view) == 0xd.a763fc8cb9ff9e6p+1325L;
153 
154 view = DecimalView!size_t(false, 309, BigUIntView!size_t.fromHexString("1"));
155 should(cast(float)view) == float.infinity;
156 should(cast(double)view) == double.infinity;
157 static if (real.mant_dig >= 64)
158     should(cast(real)view) == 0xb.201833b35d63f73p+1023L;
159 
160 view = DecimalView!size_t(false, 308, BigUIntView!size_t.fromHexString("2"));
161 should(cast(float)view) == float.infinity;
162 should(cast(double)view) == double.infinity;
163 static if (real.mant_dig >= 64)
164     should(cast(real)view) == 0x8.e679c2f5e44ff8fp+1021L;
165 
166 view = DecimalView!size_t(false, 308, BigUIntView!size_t.fromHexString("2"));
167 should(cast(float)view) == float.infinity;
168 should(cast(double)view) == double.infinity;
169 static if (real.mant_dig >= 64)
170     should(cast(real)view) == 0x8.e679c2f5e44ff8fp+1021L;
171 
172 view = DecimalView!size_t(false, 295, BigUIntView!size_t.fromHexString("1059949B7090"));
173 should(cast(float)view) == float.infinity;
174 should(cast(double)view) == double.infinity;
175 static if (real.mant_dig >= 64)
176     should(cast(real)view) == 0x8.00000000006955ap+1021L;
177 
178 view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("0"));
179 should(cast(float)view) == 0;
180 should(cast(double)view) == 0;
181 static if (real.mant_dig >= 64)
182     should(cast(real)view) == 0L;
183 
184 view = view;
185 should(cast(float)view) == 0;
186 should(cast(double)view) == 0;
187 static if (real.mant_dig >= 64)
188     should(cast(real)view) == 0L;
189 
190 view = DecimalView!size_t(false, -325, BigUIntView!size_t.fromHexString("1"));
191 should(cast(float)view) == 0;
192 should(cast(double)view) == 0;
193 static if (real.mant_dig >= 64)
194     should(cast(real)view) == 0xa.5ced43b7e3e9188p-1083L;
195 
196 view = DecimalView!size_t(false, -326, BigUIntView!size_t.fromHexString("1"));
197 should(cast(float)view) == 0;
198 should(cast(double)view) == 0;
199 static if (real.mant_dig >= 64)
200     should(cast(real)view) == 0x8.4a57695fe98746dp-1086L;
201 
202 view = DecimalView!size_t(false, -500, BigUIntView!size_t.fromHexString("1"));
203 should(cast(float)view) == 0;
204 should(cast(double)view) == 0;
205 static if (real.mant_dig >= 64)
206     should(cast(real)view) == 0x8.33ada2003db9a8p-1664L;
207 
208 view = DecimalView!size_t(false, -1000, BigUIntView!size_t.fromHexString("1"));
209 should(cast(float)view) == 0;
210 should(cast(double)view) == 0;
211 static if (real.mant_dig >= 64)
212     should(cast(real)view) == 0x8.68a9188a89e1467p-3325L;
213 
214 view = DecimalView!size_t(false, -4999, BigUIntView!size_t.fromHexString("1"));
215 should(cast(float)view) == 0;
216 should(cast(double)view) == 0;
217 static if (real.mant_dig >= 64)
218     should(cast(real)view) == 0L;
219 
220 view = DecimalView!size_t(false, -10000, BigUIntView!size_t.fromHexString("1"));
221 should(cast(float)view) == 0;
222 should(cast(double)view) == 0;
223 static if (real.mant_dig >= 64)
224     should(cast(real)view) == 0L;
225 
226 view = DecimalView!size_t(false, -4969, BigUIntView!size_t.fromHexString("329659A941466C6B"));
227 should(cast(float)view) == 0;
228 should(cast(double)view) == 0;
229 static if (real.mant_dig >= 64)
230     should(cast(real)view) == real.min_normal * real.epsilon;
231 
232 view = DecimalView!size_t(false, -15, BigUIntView!size_t.fromHexString("525DB0200FFAB"));
233 should(cast(float)view) == 1.448997445238699f;
234 should(cast(double)view) == 0x1.72f17f1f49aadp+0;
235 static if (real.mant_dig >= 64)
236     should(cast(real)view) == 0xb.978bf8fa4d56cp-3L;
237 
238 view = DecimalView!size_t(false, -15, BigUIntView!size_t.fromHexString("525DB0200FFAB"));
239 should(cast(float)view) == 1.448997445238699f;
240 should(cast(double)view) == 0x1.72f17f1f49aadp+0;
241 static if (real.mant_dig >= 64)
242     should(cast(real)view) == 0xb.978bf8fa4d56cp-3L;
243 
244 view = DecimalView!size_t(false, -325, BigUIntView!size_t.fromHexString("1"));
245 should(cast(float)view) == 0;
246 should(cast(double)view) == 0;
247 static if (real.mant_dig >= 64)
248     should(cast(real)view) == 0xa.5ced43b7e3e9188p-1083L;
249 
250 view = DecimalView!size_t(false, -326, BigUIntView!size_t.fromHexString("1"));
251 should(cast(float)view) == 0;
252 should(cast(double)view) == 0;
253 static if (real.mant_dig >= 64)
254     should(cast(real)view) == 0x8.4a57695fe98746dp-1086L;
255 
256 view = DecimalView!size_t(false, 0, BigUIntView!size_t.fromHexString("1"));
257 should(cast(float)view) == 1;
258 should(cast(double)view) == 0x1p+0;
259 static if (real.mant_dig >= 64)
260     should(cast(real)view) == 0x8p-3L;
261 
262 view = DecimalView!size_t(false, -5, BigUIntView!size_t.fromHexString("3"));
263 should(cast(float)view) == 3e-5f;
264 should(cast(double)view) == 0x1.f75104d551d69p-16;
265 static if (real.mant_dig >= 64)
266     should(cast(real)view) == 0xf.ba8826aa8eb4635p-19L;
267 
268 view = DecimalView!size_t(false, -1, BigUIntView!size_t.fromHexString("1"));
269 should(cast(float)view) == 0.1f;
270 should(cast(double)view) == 0x1.999999999999ap-4;
271 static if (real.mant_dig >= 64)
272     should(cast(real)view) == 0xc.ccccccccccccccdp-7L;
273 
274 view = DecimalView!size_t(false, -7, BigUIntView!size_t.fromHexString("98967F"));
275 should(cast(float)view) == 0.9999999f;
276 should(cast(double)view) == 0x1.fffffca501acbp-1;
277 static if (real.mant_dig >= 64)
278     should(cast(real)view) == 0xf.ffffe5280d65435p-4L;

Meta