Move std.numeric.CustomFloat.ToBinary to top-level

This commit is contained in:
RazvanN7 2018-11-01 17:23:51 +02:00 committed by Sebastian Wilzbach
parent cbc4afc179
commit 7b357e2eb2

View file

@ -145,6 +145,27 @@ if (((flags & flags.signed) + precision + exponentWidth) % 8 == 0 && precision +
auto p = Probability(0.5);
}
// Facilitate converting numeric types to custom float
private union ToBinary(F)
if (is(typeof(CustomFloatParams!(F.sizeof*8))) || is(F == real))
{
F set;
// If on Linux or Mac, where 80-bit reals are padded, ignore the
// padding.
import std.algorithm.comparison : min;
CustomFloat!(CustomFloatParams!(min(F.sizeof*8, 80))) get;
// Convert F to the correct binary type.
static typeof(get) opCall(F value)
{
ToBinary r;
r.set = value;
return r.get;
}
alias get this;
}
/// ditto
struct CustomFloat(uint precision, // fraction bits (23 for float)
uint exponentWidth, // exponent bits (8 for float) Exponent width
@ -176,27 +197,6 @@ private:
alias Flags = CustomFloatFlags;
// Facilitate converting numeric types to custom float
union ToBinary(F)
if (is(typeof(CustomFloatParams!(F.sizeof*8))) || is(F == real))
{
F set;
// If on Linux or Mac, where 80-bit reals are padded, ignore the
// padding.
import std.algorithm.comparison : min;
CustomFloat!(CustomFloatParams!(min(F.sizeof*8, 80))) get;
// Convert F to the correct binary type.
static typeof(get) opCall(F value)
{
ToBinary r;
r.set = value;
return r.get;
}
alias get this;
}
// Perform IEEE rounding with round to nearest detection
void roundedShift(T,U)(ref T sig, U shift)
{