# Thread: Big Integer Math include file

1. ## Big Integer Math include file

After Dan's challenge (the division of the two ridiculously large integers) I started working on proper Big Integer functionality and I've had it sitting on my hard drive for some time now. I've documented it somewhat, added a test and example program, and here it is for those of you who, like me, can't do with just Quad integers.

Big Integers are what the name says: big. In thinBasic the largest integer data type is Quad: signed 64-bit integers. Although the numbers you can describe in those 64 bits are huge, sometimes they're not huge enough. Which is where BigInt comes in.

The size of a BigInt is limited by only three things: (1) your computer's memory, (2) thinBasic's "limit" of 2GB for a string, and (3) your patience. Make no mistake, number three could be the killer. This is written in straight thinBasic, not assembler, and although you will get a result, you may have to wait for a while. But do not despair: calculating the 13th root of a 200-digit number (included as an example) takes 0.0542 seconds on my computer.

I've added as many functions dealing with integers as I could come up with. I haven't gone the way of stuff like Graham's Number but if you want to know the two millionth Fibonacci number, or the factorial of your birthday, here's your chance.

The source code contains minimal comments (basically a short description of the function) and that's it. I did not document the code itself, mainly because I "get" the stuff that I programmed but also because I would be giving a course in mathematics and binary arithmetic if I did. Not for free Chester.

Anyway, see the attached and the small documentation file. (Had to zip that because I got an upload error for the file.) If you have some questions about how to use it all, have a look at the test and example scripts. If that doesn't help you, ask here and you may receive.

Have fun with it. I did.

2. ## Almost forgot...

I've put in an Easter Egg.

The people most likely to find this Easter Egg are code browsers and people with thick fingers (ie. people making typing errors). If you find the Easter Egg let me know what you think of it. If you understand what it is, that is.

I'll give you one small hint (completely useless, so I might as well give it), and because 13 is my favourite number, this is it:

13 is 13 long

3. Can't wait for someone to solve the Easter Egg.

Here is the only thing, I can find.
http://primes.utm.edu/curios/page.php/4294967295.html

Another thing that I saw that I have no idea is "42_13"
42 the answer to the universe and everything alongside your favorite number 13

Boy, you did a lot of work.

I don't understand it, but it looks good to me.

I like the 13th root calculation.

And, I like the test of all of your functions. That test code is really something.

And, I like your documentation. Some of those functions, like, BigInt_Nrt, look amazing.

Humbly,
Dan

5. Originally Posted by kryton9
Another thing that I saw that I have no idea is "42_13"
42 the answer to the universe and everything alongside your favorite number 13
That's in the test function. And of course that's straight out of Douglas Adams' Hitch-Hiker's Guide to the Galaxy.

When they find out the Answer to Life, the Universe and Everything is '42' they build Earth (the planet) to find out what the question is. In the end they try to find the question using Scrabble tiles. The tiles run out but what they get is:

What do you get if you multiply six and nine?

Someone, later, suggested that if they had had enough tiles the complete question would have had after that: "in base thirteen".

It's just a test case. It's not the Easter Egg. The Easter Egg is in the main code and the hint is of no help at all finding it. Only when you've found it will you understand what the hint means.

6. I too do not understand the details but this is a huge and great work !
Thank you very much.

It also seems perfect for a compiled thinBasic module that would burst execution speed by a factor of 100 or even more.

7. ## A proper hint for the Easter Egg...

Otherwise some poor soul will have to go through the code line by line. Here is a proper hint and it should lead you directly to the Easter Egg.

all your base IS belong to us

And that's all I'm going to say about it.

8. Spotted a typing error in the main script but because thinBasic is very forgiving it doesn't affect anything. Line 983 (in BII_mul) has the +\$NUL outside of the CVDWD bracket, which is incorrect.

Originally the line reads n=CVDWD(Mid\$(b,i,3))+\$NUL but this should be n=CVDWD(Mid\$(b,i,3)+\$NUL). (Changing it to n=CVDWD(Mid\$(b,i,3)) would probably also work.)

For the less adventurous the corrected include script is below.

9. Hi Johaness,

thanks a lot, I am going step by step and the library looks very good to me so far.
I was confused at first, but then I realised I cannot use passed strings directly, but need to use the BigInt_FromString and BigInt_ToString.

I found one more typo:
```Function BigInt_Abs(a As String) As String
Return BigIntPos(a)
End Function
```
should be:
```Function BigInt_Abs(a As String) As String
Return BigInt_Pos(a)
End Function
```
Petr

10. Petr,

Thanks for the input. I should also have put the aliases in the test script. Forgot all about ABS because I started out with Pos and Neg.

Seeing that you have been looking at the source closely, have you found the Easter Egg?

Page 1 of 2 12 Last

There are no members to list at the moment.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•