Home › C and C++ › Visual C++

It looks like you're new here. If you want to get involved, click one of these buttons!

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 629 Off topic board
- 217 Mobile & Wireless
- 89 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 151 WEB-Services / SOAP

HackItSoft
Member Posts: **2**

in Visual C++

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.

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.

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

41: 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.

2: 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.

41: : 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.