Use "giant" numbers

BlitzPlus Forums/BlitzPlus Programming/Use "giant" numbers

Vignoli(Posted 2007) [#1]
Hello

I need help about using very very bigs numbers in blitz. I know an integer use 4 bytes, but it's not enough for the program i'm doing.
Is there a possibility to work with number up to 10^20 ?
(I think it may be possible by joining integers together by i don't know how)

Thanks


CS_TBL(Posted 2007) [#2]
The longest var in Blitz is 4 bits, the longest var in Blitzmax is 8 bits. Basically you can do math with any number (in asm you'd be using the carry flag for that iirc), just as we ppl can do math with any number ourself. But for that you'd be doing custom calc routines. There's no native blitz stuff for >4bits calculations afaik.


Vignoli(Posted 2007) [#3]
Thanks for you answer.

I'll search on the web to find some calc routines on any programmation language, and try to convert them in blitz.

I juste have to use: modulo, addition, substraction, and multiplication by 2.

If I do not find it on the web, i'll have to search my old assembler tutorials... :-)


Oso(Posted 2007) [#4]
If excessive speed is not an issue then I have used two methods which seem to work fine.

1. Use strings.

2. Use types containing integer fields, each for a section of the number - small enough to escape overflow during operations - mod 10000 works. This is faster than strings.

In either case just write your own arithmetic functions to suit your purpose. Division and special functions require a little ingenuity but if you only need addition and multiplication it's dead easy.


Oso(Posted 2007) [#5]
I used such strings to search for certain solutions of Mordell's equation and various sorting algorithms to do with numbers (don't ask why - just idle speculation) and I was surprised how quickly everything ran despite all the useless overhead.


Timjo(Posted 2007) [#6]
Just out of curiosity - What is Mordell's equation?


Oso(Posted 2007) [#7]
Y^2=X^3+K where X,Y and K are integers.