Huge #'s

Just starting out? Need help? Post your questions and find answers here.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Huge #'s

Post by michaeled314 »

Could someone give me a way to account for huge huge numbers w/out having to use a plugin-library
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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)
Dare2 cut down to size
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

A 60-digit #
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

Anyone have any tips?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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. :)
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:)

And with friends like Dare... :wink:
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

srod wrote::)

And with friends like Dare... :wink:
... who needs enemas? :D
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

It is for Project Euler at http://www.projecteuler.net
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

So could anyone give me a way to handle 60-digit #'s w/out having to use a plugin library
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

Found add but not multiply
Post Reply