I’ve been trying to make a custom math node for factorial function using recursion in my script, but I’ve been getting errors and it seems to me that the “self referencing” part is the issue because whenever i remove it the script runs fine. I’m not sure if there is something wrong with my syntax or does OSL simply not work with recursion.
Here’s my code:
shader factorial(
int i = 1,
output int o = 0)
{
int fac(int n){if (n == 0)
{
return 1;
}
else
{
return (n * fac(n-1));
}
}
o = fac(i);
}