Insanely small decimals
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?
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]
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]
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.
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.
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.
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?
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..
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..
Quote:Original post by HAMQuote: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.
It's hard to argue with Google [grin]
On a more serious note, your math is correct. The answer is going to be insanely small as 0.5^1000000 = 1/(2^1000000). For reference, 2^x is approximately 10^(x/3) so 2^1000000 is about the same as 10^333333.
On a more serious note, your math is correct. The answer is going to be insanely small as 0.5^1000000 = 1/(2^1000000). For reference, 2^x is approximately 10^(x/3) so 2^1000000 is about the same as 10^333333.
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement