# How to get an exponent?

Hi, I have a variable of type double, and I need to get an exponent from this variable to another variable.

For example:

double a = 123.45;
int E;
...
E = ???(a); //in that case exponent (E) will be -2 (12345*10-2)(I hope so...)

and also somehow get effective numbers to other variable (long N = ???(a)) //here it wil be 12345 (or maybe use some other type, or storage process if type long isn't big enaugh)

And the most important - it needs to be very, VERY fast. I want to use it in a special sorting algorythm, it work quite well for integer values (it sorts much more faster than quick sort),but for real numbers it needs a little different architecture. So, please help me someone.

• : Hi, I have a variable of type double, and I need to get an exponent
: from this variable to another variable.
:
: For example:
:
: double a = 123.45;
: int E;
: ...
: E = ???(a); //in that case exponent (E) will be -2 (12345*10-2)(I
: hope so...)
:
: and also somehow get effective numbers to other variable (long N =
: ???(a)) //here it wil be 12345 (or maybe use some other type, or
: storage process if type long isn't big enaugh)
:
: And the most important - it needs to be very, VERY fast. I want to
: use it in a special sorting algorythm, it work quite well for
: integer values (it sorts much more faster than quick sort),but for
: real numbers it needs a little different architecture. So, please
: help me someone.
:
E=(int)(floor(log10(E)));
Not sure if it is what you're looking for or if it is fast enough to meet your standards, though.
The above gives the exponent for scientific notation. I believe it is impossible to quickly determine the exponent you are looking for, as floating points are stored in binary format, leading to an infinite repeating pattern of bits for most decimals.
• : E=(int)(floor(log10(E)));
: Not sure if it is what you're looking for or if it is fast enough to
: The above gives the exponent for scientific notation. I believe it
: is impossible to quickly determine the exponent you are looking for,
: as floating points are stored in binary format, leading to an
: infinite repeating pattern of bits for most decimals.

Thanks, but I need something little different. That code gives me something like a count of number in variable minus 1 (for example: for 963 it gives 2, for 9638 gives 3...; and for 0.555 it gives -1 (for all 0.xxxxx it returns -1)
But I need to get (probably from the binary form, because complicated calculations will be too slow) the shift of effective numbers against the 0.
examples:
123456789 E = 0 (123456789 * 10 ^0) //9 effective numbers
123000000 E = 6 (123 * 10 ^6) //3 effective numbers
0.000123 E = -6 (123 * 10 ^-6) //also 3 effective numbers

I think it can be done fast, as I know data is stored in two variables - fist contains effective numbers, and other exponent, right? So extract one of them should be possible (maybe in assembler, why not?). I can get exponent by calculation, but it wil be slow, and for my purposes totally uselles.
• : : E=(int)(floor(log10(E)));
: : Not sure if it is what you're looking for or if it is fast enough to
: : meet your standards, though.
: : The above gives the exponent for scientific notation. I believe it
: : is impossible to quickly determine the exponent you are looking for,
: : as floating points are stored in binary format, leading to an
: : infinite repeating pattern of bits for most decimals.
:
: Thanks, but I need something little different. That code gives me
: something like a count of number in variable minus 1 (for example:
: for 963 it gives 2, for 9638 gives 3...; and for 0.555 it gives -1
: (for all 0.xxxxx it returns -1)
: But I need to get (probably from the binary form, because
: complicated calculations will be too slow) the shift of effective
: numbers against the 0.
: examples:
: 123456789 E = 0 (123456789 * 10 ^0) //9 effective numbers
: 123000000 E = 6 (123 * 10 ^6) //3 effective numbers
: 0.000123 E = -6 (123 * 10 ^-6) //also 3 effective numbers
:
:
: I think it can be done fast, as I know data is stored in two
: variables - fist contains effective numbers, and other exponent,
: right? So extract one of them should be possible (maybe in
: assembler, why not?). I can get exponent by calculation, but it wil
: be slow, and for my purposes totally uselles.
:
A floating point is seperated into two variables, the mantissa and exponent, as you have described, but they are not decimals with a decimal exponent, but they are a string of binary digits with a binary exponent.