The OpenD Programming Language

Fp.opCast

  1. T opCast()
  2. T opCast()
    struct Fp(uint size)
    nothrow const
    T
    opCast
    (
    T
    bool noSpecial = false
    bool noHalf = false
    )
    ()
    if (
    is(T == float) ||
    is(T == double)
    ||
    is(T == real)
    )
    if (
    size % (uint.sizeof * 8) == 0 &&
    size >= (uint.sizeof * 8)
    )
  3. T opCast()

Examples

import mir.bignum.fixed: UInt;
auto fp = Fp!128(1, 100, UInt!128.fromHexString("e3251bacb112cb8b71ad3f85a970a314"));
assert(cast(double)fp == -0xE3251BACB112C8p+172);

fp = Fp!128(1, long.max, UInt!128.init);
assert(cast(double)fp == -double.infinity);

import mir.math.ieee : signbit;
fp = Fp!128(1, long.max, UInt!128(123));
auto r = cast(double)fp;
assert(r != r && r.signbit);
import mir.bignum.fixed: UInt;
auto fp = Fp!128(1, 100, UInt!128.fromHexString("e3251bacb112cb8b71ad3f85a970a314"));
static if (real.mant_dig == 64)
    assert(cast(real)fp == -0xe3251bacb112cb8bp+164L);
import mir.bignum.fixed: UInt;
auto fp = Fp!64(1, 100, UInt!64(0xe3251bacb112cb8b));
version (DigitalMars)
{
    // https://issues.dlang.org/show_bug.cgi?id=20963
    assert(cast(double)fp == -0xE3251BACB112C8p+108
        || cast(double)fp == -0xE3251BACB112D0p+108);
}
else
{
    assert(cast(double)fp == -0xE3251BACB112C8p+108);
}
import mir.bignum.fixed: UInt;
auto fp = Fp!64(1, 100, UInt!64(0xe3251bacb112cb8b));
static if (real.mant_dig == 64)
    assert(cast(real)fp == -0xe3251bacb112cb8bp+100L);

Meta