Jump to content
  • Advertisement
Sign in to follow this  
Kevinator

Insanely small decimals

This topic is 4870 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. Say I needed to calculate the value of the expression 0.5^1000000. I don't even have the slightest idea how to start. Here is a sample of the relevant part of the data: 0.5^1072: 2.0E-323. 0.5^1073: 1.0E-323. 0.5^1074: 4.9E-324. 0.5^1075: 0.0. 0.5^1076: 0.0. ... 0.5^1000000: 0.0. The value cuts out around 325 decimal places. I need to maintain the true value out to the millionth power. Does anyone have any idea how I might do this?

Share this post


Link to post
Share on other sites
Advertisement
It all depends on what you're wanting to do with it, which would be...?

In other words, what do you really mean by calculate? Do you just want to print the result, including all the zeros? Or do you want to multiply it by something? Of course, to print it out in binary, you just output the appropriate number of zeros followed by a one, so they're be nothing to calculate as such, if base two was your output...

You may want to take a look at "libmp++".
[google]

Share this post


Link to post
Share on other sites
Well since your precision is going to vary widely say (10^10 to 10^10^10^10) Then you might want to look into the (NTL) Number theory library.



If you were working with a bunch of really small numbers (all basilcy the same precision) it would be easy. You could just use the floats like normal and then adust the final data later. But it seems like your data will be of a wide range of precision.

Share this post


Link to post
Share on other sites
To answer your question, my final goal is to print out the full number in base 10 (to the console or a file, whatever). I would even settle for an approximation, like 3.4E-3456 or something as long as its somewhat accurate. I just want to know the value of 0.5 to the millionth power. 0.0 is not an acceptable answer to me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kevinator
To answer your question, my final goal is to print out the full number in base 10 (to the console or a file, whatever). I would even settle for an approximation, like 3.4E-3456 or something as long as its somewhat accurate. I just want to know the value of 0.5 to the millionth power. 0.0 is not an acceptable answer to me.


Hmm Try the NTL.

BTW could you maybe comment on why?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well.. GMP and BCMath might be able to help you.. I think they are free and opensource, with like a BSD license..


I tried 999..99 (50x nines) ^ 1024.. The answer was 57200 digits, and I think it took quite a bit below the second to complete that computation on my 700mhz comp.. That's using BCMath.. So I suggest you check it out.. Don't have a link, but google should be able to help you..

Share this post


Link to post
Share on other sites
Quote:
Original post by HAM
Quote:
Original post by Kevinator
To answer your question, my final goal is to print out the full number in base 10 (to the console or a file, whatever). I would even settle for an approximation, like 3.4E-3456 or something as long as its somewhat accurate. I just want to know the value of 0.5 to the millionth power. 0.0 is not an acceptable answer to me.


Hmm Try the NTL.

BTW could you maybe comment on why?


Sure. :) If I'm not mistaken, 0.5^1000000 is the probability of flipping a coin and having it land on heads a million times in a row. If my math is incorrect please set me straight. Thanks for the suggestions, I will check out the libraries you have suggested.

Share this post


Link to post
Share on other sites
0.5^1000000 is the same as 10^(lg(0.5) * 1000000) or 10^(- lg(2) * 1000000) where lg is the decimal logarithm (lg(x) = ln(x) / ln(10), whatever logarithm is ln)

Therefore, 0.5^1000000 is roughly 10^-301029.96875 or 10^0.03125 * 10^-301030

Now 10^0.03125 is 1.0746078 so your number is roughly 1.0746078E-301030

[Edited by - Diodor on July 22, 2005 2:27:02 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!