Problem about math function - pow

I encounter this segment problem for the second line of the code.

#include <cmath>
const float dx = 1.0E-3, dy = 1.0E-3, dz = 1.0E-3;
const float dt = 0.99/pow( 1.0/pow(dx, 2)+1.0/pow(dy, 2)+1.0/pow(dz,2), 0.5);

but after I changed to

const float dt = 0.99/ sqrt( 1.0/(dx*dx) + 1.0/(dy*dy) + 1.0/(dz*dz) );

it works.

I am confused. Please help.

Break the formula down into multiple computations and verify that every divisor is not 0. My guess is that you are hitting a divide by 0 error in your code due to rounding/underflow.

The problem is implementation dependent because it does not fail on x86_64 Linux with GCC 4.3. What platform/compiler are you using?
Topic archived. No new replies allowed.