Finding the decimal power of a float without a logarithm...

Hello Readers,

I have the problem, that I have to find the order of magnitue (decimal) of a float.
I do not want to use a logarithm, so at first I thought about something like this:

  float x=0.01;
  int a=0;
    for(float b=x;b<1.0;b*=10.0){
        Serial.println(b); 
        a--;
        Serial.println(a);
    }

The problem is, that the float is not accurate. So in the case of x=0.01 one will get on the serial monitor:

0.01
-1
0.10
-2
1.00
-3

Are there other ways to do this?

In hope for a soon answer,
Kischy

You could pick apart the binary exponent of the float and the sign, and convert to decimal.
Google "IEE 754"

AWOL:
You could pick apart the binary exponent of the float and the sign, and convert to decimal.
Google "IEE 754"

Well the frexp function (assuming the Arduino library includes it) will do the basic job to return the power of 2 exponent via the int pointer passed as the second argument. But that still will take some calculations to get the correct power of 10.

That's helpful, thank you!

Just out of curiosity, why are you avoiding the logarithm?