I'm trying to calculate a simple approximation to an integral by dividing it up into a step function, easy stuff. The problem starts when I simply try to do a division. Here is my code:
double integrand(int a, double div, int n) {
int i;
double sum, val;
val = 1.0/div;
for(i = 0; i < div; i++) {
sum = sum + (pow(i*val, n)/(i*val + a)) * val;
}
return sum;
}
Here div is actually an integer, I tried bringing it into the integrand function originally as an integer and typecasting it to a double inside the function, with the same result. When I debug the code, div can be say, 100, yet val will return something ludicrous like -7.2008557565654656e+304. As far as I'm aware the rest of the code is correct, but I just cannot figure this out, what's going on?!