system
December 9, 2009, 2:15pm
1
I wanna do that kind of calc:
Example: Cubic Root of 64:
float expo = 1/3;
int cubicRoot = pow(64, expo); //the answer is 4
Serial.println(cubicRoot); //but isn't right... it prints 1
Somebody knows what is the trouble here!? :-[
Do you know another way to do that?
640 = 1.
(Because 1 / 3 = 0)
Try
"float expo = 1.0 / 3.0;"
or even
"float expo = 1 / 3.0;"
should be sufficient.
[edit]BTW, this is not a hardware issue.[/edit]
westfw
December 9, 2009, 3:59pm
3
Don't forget to "round", or even with Groove's fix you may get "3" rather than 4, because
a float value of 3.9999123 (or whatever) cast to an int truncates...
system
December 9, 2009, 4:53pm
4
:o Shame on me! LOL
Thank you guys...
It works now! ;D
I put 1.0 / 3... and it works perfectly!
(Sorry... I put that post in wrong place)