Page 1 of 6

Huge #'s

Posted: Sat Jul 14, 2007 1:15 am
by michaeled314
Could someone give me a way to account for huge huge numbers w/out having to use a plugin-library

Posted: Sat Jul 14, 2007 1:24 am
by Dare
How huge is huge?

There is quad (varname.q as 8 byte 64 bit integer)
There is double (varname.d as 8 byte 64 bit float/real)

Posted: Sat Jul 14, 2007 1:25 am
by michaeled314
A 60-digit #

Posted: Sat Jul 14, 2007 4:20 am
by michaeled314
Anyone have any tips?

Posted: Sat Jul 14, 2007 5:34 am
by netmaestro
There are bignum dlls around the web if you do a google search. It shouldn't be too hard to find one that'll work well with PB. They are usually string-based and have all their own math functions for the various operations, usually including factorials. All the functions will probably take in and return a string, and there's usually not a practical limit on the number of digits they'll work with. After all, that's the whole point. You could write something in PureBasic, but this is a wheel that's been invented and optimized many times over already, so it's just a matter of finding a freely shared one. There's several, I know.

Posted: Sat Jul 14, 2007 8:02 am
by gnozal
A well known big numbers lib is GMP : http://gmplib.org/

And here are some threads about how to use it with PB :
http://purebasic.fr/english/viewtopic.php?t=22635
http://www.purebasic.fr/french/viewtopic.php?t=6849

Posted: Sat Jul 14, 2007 10:17 am
by Dare
michaeled314 wrote:A 60-digit #
Okay, that is huge! :)

Sorry, I think you are going to have to use an external lib (such as mentioned above).

Just out of curiosity, what is this for?

If it is to handle your bank balance I want to be your friend. :)

Posted: Sat Jul 14, 2007 11:28 am
by srod
:)

And with friends like Dare... :wink:

Posted: Sat Jul 14, 2007 12:21 pm
by Dare
srod wrote::)

And with friends like Dare... :wink:
... who needs enemas? :D

Posted: Sat Jul 14, 2007 12:28 pm
by srod
:lol:

Posted: Sat Jul 14, 2007 3:29 pm
by michaeled314
It is for Project Euler at http://www.projecteuler.net

Posted: Sat Jul 14, 2007 8:37 pm
by michaeled314
So could anyone give me a way to handle 60-digit #'s w/out having to use a plugin library

Posted: Sat Jul 14, 2007 9:03 pm
by srod
Without a library, you'll have to write your own routines. The most obvious way would be to use strings.

To be honest though, you'll be reinventing the wheel! Depends how much of a rush you're in I guess.

Posted: Sat Jul 14, 2007 11:12 pm
by Michael Vogel
michaeled314 wrote:It is for Project Euler at http://www.projecteuler.net
Hi Michael,

the problems of project euler (at least the first 100 of them;) can be solved without any external library just with pure purebasic :wink:

If you've to handle longer numbers, you need usually only the functions add and multiply, you can find procedures for doing that job at... >>surprise<< http://www.purebasic.fr/english/viewtop ... 85&start=0 within my first code posting...

If you're able to optimize my routines (for speed) or even add some more functions (like div, sub) you'll be a hero (or something like that :P)

Michael

Posted: Sat Jul 14, 2007 11:24 pm
by michaeled314
Found add but not multiply