Calculating fractional exponent

Hello forum,

I have an interesting project that measures depth of water in a channel (done by measuring ultrasonic sensor distance from water) and by adding this value to a formula I can calculate the current flow.

My probem is that the formula contains a fractional exponent, and looks like this:

int waterDepth;

float flow = 11.543 * waterDepth{to the power of}2.762

Is there a way to get this done in the Arduino IDE?

Thanks

Got it:

float flow = 11.543 * pow(float(waterDepth), 2.762);

Why do you cast 'waterDepth' to a float?

I was under the impression I may need that to keep accuracy.

Will it change anything if I drop it?

heinburgh:
I was under the impression I may need that to keep accuracy.

Will it change anything if I drop it?

What accuracy do you have in the first place? You never revealed the part of the code where you declared the variable. But mathematically, you can only lose accuracy by converting to float, if what you start with is an integer. This perfectly illustrates the problem with posting only a "snippet" of code. We have no idea what the type of the variable is, or what typical values might be.

Edit - okay there is some doubt in my mind whether I just missed it, or you went back and edited the first post. Aha, so it's an integer. Well, casting it to a float is futile because the compiler will do an implicit cast to float when it detects that the expression contains float types.

For example, '5 + 7' is an integer expression, which yields an integer, 12.

'5 + 7.0' is a float expression and yields a float, 12.0