Jump to content
  • Advertisement
Sign in to follow this  
JamesCobras

Really Really Really Long Numbers C++

This topic is 2857 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 guys, i want to do some maths on a computer using massive numbers like 2^1000000.

I know this will fit into ram.

But how should i go about creating this value in ram so i can X / + - with it.

I also need perfect accuracy so short-cuts won't work.

Do i have to define my own type?

Is there a lib. for it?

Where do i start?

Any help/comments welcome.

JamesCobras

Share this post


Link to post
Share on other sites
Advertisement
You could use a bignum or multiprecision library like GMP. Or just use a language that has built in bignum primitives like Python.

Share this post


Link to post
Share on other sites
Cheers, i think that's exactly what i wanted.

I want to use C++ as opposed to python or others as it feels faster, which is really important in the application i have in mind.

Cheers

JamesCobras

Share this post


Link to post
Share on other sites
Quote:
Original post by JamesCobras
the application i have in mind.


Which is?

On my machine, Python takes about 1/10 of a second to calculate the factorial of 10,000. (The resulting number takes more than 118,000 bits to store.) Are you sure you aren't overstating your performance requirements?

Share this post


Link to post
Share on other sites
My guess would be that the performances on C++ and python are very similar, since the code for the python's arithmetics is written and executed in plain C (you could save yourself some function calls by using C++, but it's most likely going to be a drop in the bucket).

Share this post


Link to post
Share on other sites
Fortran. Never used it but my old c++ instructor mentioned it in class and how engineers should learn it. If it's some out dated language, then I'm sorry. >.<

Share this post


Link to post
Share on other sites
The application is going to be an array of functions, the first part will be finding large primes and other large number calculations.

Share this post


Link to post
Share on other sites
Quote:
Original post by JamesCobras
The application is going to be an array of functions, the first part will be finding large primes and other large number calculations.
If you were to sell your application how would you describe it to people to get them to buy it?

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
On my machine, Python takes about 1/10 of a second to calculate the factorial of 10,000.

Sad. Mine takes about 1/5th of a second.

>>> import cProfile
>>> from math import factorial
>>> cProfile.run('factorial(10000)')
3 function calls in 0.191 CPU seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.191 0.191 <string>:1(<module>)
1 0.191 0.191 0.191 0.191 {math.factorial}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!