so Wrote:

> Basically what i am asking is hmmm, ability to write generic constants? :)
> 
> Thanks!

Hi,

When writing generic FP code i always use real literals and cast to T, or int. 
I suggest doing this.
Like:

T exp3(T)(T x)
{
        if (x < cast(T)(-1.15365L))
        {
                return 0;
        }
        else
        {
                return cast(T)1.L + x * (cast(T)1.0L + x * (cast(T)0.5L + x * 
cast(T)0.3333333333333L));
        }
}


I assume the compiler will be able to optimize the cast in release mode.

If you really wan't to prevent this cast in debug mode, you can simply go with:

const T myConst = 0.3L;

then the cast will be compile-time. 

Reply via email to