On Friday, 9 June 2017 at 16:42:31 UTC, ketmar wrote:
Basile B. wrote:
Yes, easy to do, a template alĂ  octal or hexString.

can you show it, please? remember, CTFE-able!

Sure, here's a dirty draft:

template binFloat(string sign, string exp, string mant)
{
    enum s = sign == "+" ? "0" : "1";
    const b = mixin("0b" ~ s ~ exp ~ mant);
    pragma(msg,"0b" ~ s ~ exp ~ mant);
    enum binFloat = *cast(float*) &b;
}

unittest
{
static assert(binFloat!("+", "10000000", "10000000000000000000000") == 3.0f); static assert(binFloat!("-", "10000000", "10000000000000000000000") == -3.0f);
}

Reply via email to