sqrt(2) must go

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Oct 19 10:13:29 PDT 2011


You could maybe ease transition for people that rely on this behavior via:

import std.traits;

auto sqrt(F, T)(T x) { return sqrt(cast(F)x); }

auto sqrt(F)(F f)
    if (!isIntegral!F)
{
    return sqrt(f);
}

void main()
{
    int x = 1;
    sqrt(4);         // ng
    sqrt!float(x);   // ok
    sqrt(4.5);       // ok
}

It sure is shorter to type than cast(float). Then again it's templated
so maybe that's not too nice for std.math.


More information about the Digitalmars-d mailing list