Base 10 exponent of a float

May 28, 2010 4 Replies

Hi folks-



I think my brain is blocked and google isn't showing any solutions:



Does anyone know of a way in C code to get the base 10 integer exponent of a single precision float?



Thanks, John.


--- news://freenews.netfront.net/ - complaints: snipped-for-privacy@netfront.net ---


I'm not sure what you are getting at :< (perhaps parentheses in your question would make it clearer :> )

I.e., do you want the exponent field of the float expressed as a decimal integer? For example:

int exponent; double fraction = frexp((double) x, int &exponent); print("The exponent is %d.\n", exponent);

Could you represent your float algebraically in terms of the quantity you are after to be more clear? I.e., for the above:

x = fraction * (2 ** exponent)

(more or less)

floor(log10(x))

Tim Wescott Control system and signal processing consulting www.wescottdesign.com

Thanks, Tim. That worked! I knew it was something simple.

JJS

--- news://freenews.netfront.net/ - complaints: snipped-for-privacy@netfront.net ---

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required