Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Themonkster

math question large very very large numbers

This topic is 5576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Folks, I have not had to do math for a long time so here goes. I have this number I will call it number1: 6.6772148321E+142 which is this number number2: 6677214832100000150300400003230070200102400000648021026160026160021600021600000000051000102000153000204000255005100051510051102005115300512040051 converted to a double. now my problem is how do I turn number1 back into number2. is it possiable? I am writing this in a VB app also but if I have to change to another lanuage then I shall. Thanks

Share this post


Link to post
Share on other sites
Advertisement
multiply the first part (before the E) by 10 raised to the power of the second part (after the E, including the + or -).


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
You can''t : doubles only have finite precision (~15 digits, IIRC). You need a multiprecision library, type, class or whatever is available used in VB.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
quote:
Original post by Themonkster
so is this a oneway conversion?



Yes. Your number takes about 475 bits to store*, and a double is (usually) 64 bits. Data has been lost during the conversion to double, and cannot be recovered.

* The size in bits required to store an unsigned integer is its logarithm in base 2, rounded up.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
shame.

so those 2 numbers have a different value then.

anyone think another way to do it.

change number2 to a smaller size that is still the same value.

Share this post


Link to post
Share on other sites
quote:
Original post by Themonkster
...how do I turn number1 back into number2.




Do you mean "how do I display the number without using scientific notation?", or do you mean "how do I convert number1 from floating-point to a integer?"?

Share this post


Link to post
Share on other sites
The answer is already here. The E+142 signifies that there should be 142 digits left of the decimal place (not the most mathematically correct definition, but practical).

So:

StringVersionOfVariable = CStr(DoubleVariable)
PowerOfVariable = Mid(StringVersionOfVariable, Instrrev(StringVersionOfVariable, "E") + 2)

Then use string processing to extract the mantissa (6.677 etc) and flatten it into a single string: 66772148321 with no decimal.

Now just figure out how many zeroes you need to slap on the end in order to fill 142 digits, and stick ''em on.

Only works for numbers > 1.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!