The OpenD Programming Language

Fp.this

Constructs Fp from hardaware floating point number.

  1. this(bool sign, long exponent, UInt!size normalizedCoefficient)
  2. this(T value, bool normalize)
    struct Fp(uint size)
    @safe pure nothrow @nogc
    this
    (
    T
    )
    (
    const T value
    ,
    bool normalize = true
    )
    if (
    T.mant_dig <= size
    )
    if (
    size % (uint.sizeof * 8) == 0 &&
    size >= (uint.sizeof * 8)
    )
  3. this(UInt!isize integer, bool normalizedInteger)
  4. this(ulong value)
  5. this(long value)
  6. this(int value)
  7. this(uint value)

Parameters

value T

Hardware floating point number. Special values nan and inf aren't allowed.

normalize bool

flag to indicate if the normalization should be performed.

Examples

enum h = -33.0 * 2.0 ^^ -10;
auto f = Fp!64(h);
assert(f.sign);
assert(f.exponent == -10 - (64 - 6));
assert(f.coefficient == 33UL << (64 - 6));
assert(cast(double) f == h);

// CTFE
static assert(cast(double) Fp!64(h) == h);

f = Fp!64(-0.0);
assert(f.sign);
assert(f.exponent == 0);
assert(f.coefficient == 0);

// subnormals
static assert(cast(float) Fp!64(float.min_normal / 2) == float.min_normal / 2);
static assert(cast(float) Fp!64(float.min_normal * float.epsilon) == float.min_normal * float.epsilon);
// subnormals
static assert(cast(double) Fp!64(double.min_normal / 2) == double.min_normal / 2);
static assert(cast(double) Fp!64(double.min_normal * double.epsilon) == double.min_normal * double.epsilon);
// subnormals
static if (real.mant_dig <= 64)
{
    static assert(cast(real) Fp!128(real.min_normal / 2) == real.min_normal / 2);
    static assert(cast(real) Fp!128(real.min_normal * real.epsilon) == real.min_normal * real.epsilon);
}

enum d = cast(float) Fp!64(float.min_normal / 2, false);

// subnormals
static assert(cast(float) Fp!64(float.min_normal / 2, false) == float.min_normal / 2, d.stringof);
static assert(cast(float) Fp!64(float.min_normal * float.epsilon, false) == float.min_normal * float.epsilon);
// subnormals
static assert(cast(double) Fp!64(double.min_normal / 2, false) == double.min_normal / 2);
static assert(cast(double) Fp!64(double.min_normal * double.epsilon, false) == double.min_normal * double.epsilon);
// subnormals
static if (real.mant_dig <= 64)
{
    static assert(cast(real) Fp!64(real.min_normal / 2, false) == real.min_normal / 2);
    static assert(cast(real) Fp!64(real.min_normal * real.epsilon, false) == real.min_normal * real.epsilon);
}

import mir.bignum.fixed: UInt;

assert(cast(double)Fp!128(+double.infinity) == +double.infinity);
assert(cast(double)Fp!128(-double.infinity) == -double.infinity);

import mir.math.ieee : signbit;
auto r = cast(double)Fp!128(-double.nan);
assert(r != r && r.signbit);

Meta