floating point verification using is?

bearophile bearophileHUGS at lycos.com
Fri Dec 18 18:47:22 PST 2009


Unfortunately the asm produced by ldc shows the call to the array equality function still. Fifth try:


bool isInitNaN(T)(T x) if (isFloatingPoint!T) {
    union FPData {
        T f;

        static if (T.sizeof == uint.sizeof) {
            uint data;
        } else static if (T.sizeof == ulong.sizeof) {
            ulong data;
        } else static if (T.sizeof == 10) {
            ulong data1;
            ushort data2;
        } else static if (T.sizeof == 12) {
            ulong data1;
            uint data2;
        } else static if (T.sizeof == 16) {
            ulong data1;
            ulong data2;
        } else {
            ubyte[T.sizeof] data;
        }
    }

    static FPData fnan, fpd;
    fpd.f = x;

    static if (T.sizeof == 10 || T.sizeof == 12 || T.sizeof == 16)
        return fnan.data1 == fpd.data1 && fnan.data2 == fpd.data2;
    else
        return fnan.data == fpd.data;
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list