Stefano Silvestri
Initiate
Hello.
I'm new to ServUO and i don't have much experience with C# (a little with c, much more with python).
I'm trying to implement an error function and a gaussian function to make a more realistic skill system. I first made it on python just to check that the numbers were right (correct normalization etc.) and then i "translated" it on c#.
Boring part:
The function i tested on python has a spectrum that you can see on the attached file (nevermind the x100 on the x axis, it was there just for readability reasons), and is just an algorithm for calculating an approximation of the CDF of a gaussian, the idea was then to use it to determine the success chance.
THE question:
I implemented it with these functions
But wheneve i call Cumulative(a,b) with a=[0,1] and b=0.1,0.2 it returns NaN
Is there something that is strictrly c# related that i'm missing here?
Thanks for your attention.
I'm new to ServUO and i don't have much experience with C# (a little with c, much more with python).
I'm trying to implement an error function and a gaussian function to make a more realistic skill system. I first made it on python just to check that the numbers were right (correct normalization etc.) and then i "translated" it on c#.
Boring part:
The function i tested on python has a spectrum that you can see on the attached file (nevermind the x100 on the x axis, it was there just for readability reasons), and is just an algorithm for calculating an approximation of the CDF of a gaussian, the idea was then to use it to determine the success chance.
THE question:
I implemented it with these functions
Code:
public static double Factorial(int n)
{
int result = 1;
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
public static double erf(double x)
{
double a = 0;
int i=0;
while (i<100)
{
a+=(2/Math.Sqrt(Math.PI))*(Math.Pow(-1,i)*Math.Pow(x,(2*i+1)))/(Factorial(i)*(2*i+1));
i+=1;
}
return(a);
}
public static double Cumulative(double x, double s)
{
double cum=0;
cum=0.5*(1+erf(x/(s*Math.Sqrt(2))));
return (cum);
}
But wheneve i call Cumulative(a,b) with a=[0,1] and b=0.1,0.2 it returns NaN
Is there something that is strictrly c# related that i'm missing here?
Thanks for your attention.
Attachments
Last edited: