double - 1 divided by very large number return 0, C -
i decided post question because i'm not sure why i'm getting result. researched in site , others finding no solution. sorry if i'm violating websites rules remember, i'm new. code of function written in c returning unexpected result:
double gauss (double average, double variance, int data) { double model,power; power = ((((data-average)*(data-average))/(2*variance))*(1)); model = (pow(e,(int)power)); return 1.0/model; }
i don't know if should post rest of code if want to, wanted keep post short. issue occuring 1.0/model because model big number.
c doubles have limited precision, if divide 1.0 large double, precision error net 0 (effectively, actual answer close 0 precision error round zero).
you try use long double
more precision, think better off using arbitrary precision library gmp.
Comments
Post a Comment