12 years, 5 months ago.

what is pow?

hello i found this code:

  altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));

but mbed doesnt want to accept this, i get:

"more than one instance of overloaded function "pow" matches the argument list:" in file "/main.cpp", Line: 67, Col: 42

" function "std::pow(float, int)"" in file "/"

" argument types are: (float, double)" in file "/"

anbody has an idea? thanx in advance!

3 Answers

12 years, 5 months ago.

Try this:

altitude = (float)44330 * (1 - pow( (float)(pressure/p0), 0.190295) );

It's subtle, but this says the entire expression, "pressure/p0," is float, rather than just "pressure."

Accepted Answer

was a shot, but it didnt work

posted by Adriaan Van Steendam 16 Mar 2013

Did you see this one?

http://mbed.org/forum/mbed/topic/476/

Particularly Simon's comment?

posted by Aaron Minner 17 Mar 2013

thnx, indeed, it works

posted by Adriaan Van Steendam 17 Mar 2013
12 years, 5 months ago.

the problem is the function pow needs an integer, but i want my exponent is 0.190295 is there an other function then power??

12 years, 5 months ago.

Instead of casting pressure/p0 as a float, cast it as a double.

float altitude = (float)44330 * (1 - pow(((double) (pressure/p0)), 0.190295));

Tim

You can also declare that your exponent is a float:

float altitude = (float)44330 * (1 - pow(((float) (pressure/p0)), (float)0.190295))

http://www.cplusplus.com/reference/cmath/pow/

The standard library function pow does not have a mixed float/double or double/float input overloading. What you originally typed caused pressure/p0 to be a float while your exponent was interpreted as a double by the compiler. Explicitly declaring either the base as a double and letting the exponent be interpreted as a double, or declaring both as floats clears up the problem.

posted by Tim Zuercher 17 Mar 2013