Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed May 26, 2022
1 parent 8690f39 commit 448e2c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
18 changes: 12 additions & 6 deletions source/mir/bignum/fixed.d
Original file line number Diff line number Diff line change
Expand Up @@ -718,14 +718,20 @@ struct UInt(size_t size)
///
UInt!(size + additionalRightBits) rightExtend(size_t additionalRightBits)()
const @safe pure @nogc nothrow
if (additionalRightBits)
{
typeof(return) ret;
version (BigEndian)
ret.data[0 .. data.length] = data;
static if (additionalRightBits)
{
typeof(return) ret;
version (BigEndian)
ret.data[0 .. data.length] = data;
else
ret.data[$ - data.length .. $] = data;
return ret;
}
else
ret.data[$ - data.length .. $] = data;
return ret;
{
return this;
}
}

/++
Expand Down
25 changes: 20 additions & 5 deletions source/mir/bignum/fp.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Fp(uint size)
enum scale = T(2) ^^ T.mant_dig;
x = frexp(x, exp) * scale;
}
auto dd = this.coefficient.view.leastSignificantFirst;

static if (T.mant_dig < 64)
{
auto xx = cast(ulong)cast(long)x;
Expand All @@ -76,8 +76,12 @@ struct Fp(uint size)
auto shift = ctlz(xx);
exp -= shift + T.mant_dig + size - 64;
xx <<= shift;
this.coefficient = UInt!64(xx).rightExtend!(size - 64);
}
else
{
this.coefficient = xx;
}
dd[normalize ? $ - 1 : 0] = xx;
}
else
static if (T.mant_dig == 64)
Expand All @@ -88,8 +92,12 @@ struct Fp(uint size)
auto shift = ctlz(xx);
exp -= shift + T.mant_dig + size - 64;
xx <<= shift;
this.coefficient = UInt!64(xx).rightExtend!(size - 64);
}
else
{
this.coefficient = xx;
}
dd[normalize ? $ - 1 : 0] = xx;
}
else
{
Expand All @@ -103,15 +111,22 @@ struct Fp(uint size)
x *= scale;
auto most = ulong(high);
auto least = cast(ulong)x;
version(LittleEndian)
ulong[2] pair = [most, least];
else
ulong[2] pair = [least, most];

dd[normalize ? $ - 1 : 1] = most;
dd[normalize ? $ - 2 : 0] = least;
if (normalize)
{
this.coefficient = UInt!128(pair).rightExtend!(size - 128);
auto shift = most ? ctlz(most) : ctlz(least) + 64;
exp -= shift + T.mant_dig + size - 64 * (1 + (T.mant_dig > 64));
this.coefficient <<= shift;
}
else
{
this.coefficient = pair;
}
}
if (!normalize)
{
Expand Down

0 comments on commit 448e2c3

Please sign in to comment.