floating point verification using is?

bearophile bearophileHUGS at lycos.com
Fri Dec 18 13:07:03 PST 2009


Third try, this probably compiles better:

bool isInitNan(T)(T f) if (isFloatingPoint!T) {
    union FPInt {
        T f;
        static if (is(T == float))
            uint data;
        static if (is(T == double))
            ulong data;
        static if (is(T == real))
            ubyte[real.sizeof] data;
    }
    static FPInt fnan, fx;
    fx.f = f;
    return fnan.data == fx.data;
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list