@ats15 If your pow(x,2) is less precise or less efficient than x*x, you should file a bug with the library vendor.
@jeremi02:
1) there's the function cbrt for cube root (technically only available in standard C++ since C++11, but on most systems it has been around for 15+ years in math.h as part of the C library)
2) The value 0.2 is not a valid
double
. It lies between two doubles:
0.1999999999999999833466546306226518936455249786376953125 aka 7205759403792793 * 2
-55
and
0.200000000000000011102230246251565404236316680908203125 aka 7205759403792794 * 2
-55
it's a little closer to the second one, so when you write "0.2" in code, you're actually writing that second value, and that's what you're adding on each iteration of the loop.
Take that into account:
1 2 3 4 5
|
for(int step = 0; step <= 75; ++step)
{
double x = -5.0 + step*0.2;
// do your stuff
}
|