http://d.puremagic.com/issues/show_bug.cgi?id=5232



--- Comment #2 from Rob Jacques <sandf...@jhu.edu> 2011-03-16 17:22:28 PDT ---
Opps. Forgot that 1.0L is a real, not a long. Also, that ConvOverflowError
changed to ConvOverflowException.

/**
Narrowing numeric-numeric conversions throw when the value does not
fit in the narrower type.
 */
T toImpl(T, S)(S value)
if (!implicitlyConverts!(S, T)
        && (isNumeric!S || isSomeChar!S)
        && (isNumeric!T || isSomeChar!T))
{
    enum sSmallest = mostNegative!(S);
    enum tSmallest = mostNegative!(T);
    static if (sSmallest < 0) {
        // possible underflow converting from a signed
        static if (tSmallest == 0) {
            immutable good = value >= 0;
        } else {
            static assert(tSmallest < 0);
            immutable good = value >= tSmallest;
        }
        if (!good) ConvOverflowException.raise("Conversion negative overflow");
    }
    static if (S.max > T.max) {
        // possible overflow
        if (value >= T.max+1.0L)
            ConvOverflowException.raise("Conversion overflow");
    }
    return cast(T) value;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to