Skip to content

Commit 448e2c3

Browse files
committed
fixup
1 parent 8690f39 commit 448e2c3

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

source/mir/bignum/fixed.d

+12-6
Original file line numberDiff line numberDiff line change
@@ -718,14 +718,20 @@ struct UInt(size_t size)
718718
///
719719
UInt!(size + additionalRightBits) rightExtend(size_t additionalRightBits)()
720720
const @safe pure @nogc nothrow
721-
if (additionalRightBits)
722721
{
723-
typeof(return) ret;
724-
version (BigEndian)
725-
ret.data[0 .. data.length] = data;
722+
static if (additionalRightBits)
723+
{
724+
typeof(return) ret;
725+
version (BigEndian)
726+
ret.data[0 .. data.length] = data;
727+
else
728+
ret.data[$ - data.length .. $] = data;
729+
return ret;
730+
}
726731
else
727-
ret.data[$ - data.length .. $] = data;
728-
return ret;
732+
{
733+
return this;
734+
}
729735
}
730736

731737
/++

source/mir/bignum/fp.d

+20-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct Fp(uint size)
6767
enum scale = T(2) ^^ T.mant_dig;
6868
x = frexp(x, exp) * scale;
6969
}
70-
auto dd = this.coefficient.view.leastSignificantFirst;
70+
7171
static if (T.mant_dig < 64)
7272
{
7373
auto xx = cast(ulong)cast(long)x;
@@ -76,8 +76,12 @@ struct Fp(uint size)
7676
auto shift = ctlz(xx);
7777
exp -= shift + T.mant_dig + size - 64;
7878
xx <<= shift;
79+
this.coefficient = UInt!64(xx).rightExtend!(size - 64);
80+
}
81+
else
82+
{
83+
this.coefficient = xx;
7984
}
80-
dd[normalize ? $ - 1 : 0] = xx;
8185
}
8286
else
8387
static if (T.mant_dig == 64)
@@ -88,8 +92,12 @@ struct Fp(uint size)
8892
auto shift = ctlz(xx);
8993
exp -= shift + T.mant_dig + size - 64;
9094
xx <<= shift;
95+
this.coefficient = UInt!64(xx).rightExtend!(size - 64);
96+
}
97+
else
98+
{
99+
this.coefficient = xx;
91100
}
92-
dd[normalize ? $ - 1 : 0] = xx;
93101
}
94102
else
95103
{
@@ -103,15 +111,22 @@ struct Fp(uint size)
103111
x *= scale;
104112
auto most = ulong(high);
105113
auto least = cast(ulong)x;
114+
version(LittleEndian)
115+
ulong[2] pair = [most, least];
116+
else
117+
ulong[2] pair = [least, most];
106118

107-
dd[normalize ? $ - 1 : 1] = most;
108-
dd[normalize ? $ - 2 : 0] = least;
109119
if (normalize)
110120
{
121+
this.coefficient = UInt!128(pair).rightExtend!(size - 128);
111122
auto shift = most ? ctlz(most) : ctlz(least) + 64;
112123
exp -= shift + T.mant_dig + size - 64 * (1 + (T.mant_dig > 64));
113124
this.coefficient <<= shift;
114125
}
126+
else
127+
{
128+
this.coefficient = pair;
129+
}
115130
}
116131
if (!normalize)
117132
{

0 commit comments

Comments
 (0)