Skip to content

Commit 2dd726f

Browse files
committed
rework
1 parent 8d8c8be commit 2dd726f

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

source/mir/bignum/internal/dec2float.d

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,33 +139,18 @@ T decimalToFloatImpl(T)(ulong coefficient, long exponent)
139139
version (TeslAlgoM) {} else
140140
if (_expect(-ExponentM <= exponent && exponent <= ExponentM, true))
141141
{
142+
auto c = coefficient.Fp!64;
142143
version (all)
143144
{{
144-
auto c = coefficient.Fp!64;
145145
auto z = c.extendedMul!true(_load!wordBits(exponent));
146146
auto approx = z.opCast!(T, true);
147147
long bitsDiff = (cast(ulong) z.opCast!(Fp!wordBits).coefficient & mask) - half;
148148
uint slop = 3 * (exponent < 0);
149149
if (_expect(approx > T.min_normal && (bitsDiff < 0 ? -bitsDiff : bitsDiff) > slop, true))
150150
return approx;
151-
152-
if (0 <= exponent)
153-
{
154-
if (exponent <= MaxWordPow5!ulong)
155-
return approx;
156-
}
157-
else
158-
{
159-
if (-exponent <= MaxFpPow5!T)
160-
{
161-
auto e = _load!wordBits(-exponent);
162-
return coefficient / e.opCast!(T, true);
163-
}
164-
}
165151
}}
166152
static if (T.mant_dig < 64)
167153
{
168-
auto c = coefficient.Fp!64;
169154
auto z = c.extendedMul!true(_load!128(exponent));
170155
auto approx = z.opCast!(T, true);
171156
auto bitsDiff = (z.opCast!(Fp!128).coefficient & bigMask) - bigHalf;
@@ -175,6 +160,20 @@ T decimalToFloatImpl(T)(ulong coefficient, long exponent)
175160
if (_expect(approx > T.min_normal && bitsDiff > slop, true))
176161
return approx;
177162
}
163+
164+
if (0 <= exponent)
165+
{
166+
if (exponent <= 55) // exact exponent
167+
return approx;
168+
}
169+
else
170+
{
171+
if (-exponent <= MaxFpPow5!T)
172+
{
173+
auto e = _load!wordBits(-exponent);
174+
return coefficient / e.opCast!(T, true);
175+
}
176+
}
178177
}
179178
size_t[ulong.sizeof / size_t.sizeof] coefficients;
180179
coefficients[0] = cast(size_t) coefficient;

0 commit comments

Comments
 (0)