template bug?
Denton Cockburn
diboss at hotmail.com
Thu Feb 28 21:35:02 PST 2008
In DMD 2.011
import std.stdio;
template factorial(real n)
{
static if (n == 1)
const factorial = 1;
else const factorial = n * factorial!(n - 1);
}
void main()
{
writefln(factorial!(5));
}
produces: -3.10504e+231
when the template is changed to accept an int instead of a real, it
produces the right output: 120
What's the cause of this?
Note: in 1.027, the version accepting a real still produces the correct
output of 120.
More information about the Digitalmars-d
mailing list