I have the following function, and I tried to avoid negative values by including the if statement, but it didn't help. ...suggestions on how I might fix this...
double G(double S, double X, double r, double div, double k, double T)
{
double g=0;
g=Phi(d1(S,X,r,div,k,T))/(exp(-div*T)*S*k*sqrt(T));
if((isnan)(g) || (isinf)(g) || (g<0)) g=0;
return g;
}
2.176891e-06is really close to 0, and your program should probably consider it "essentially zero".