System BigInt

Nestharus

o-o
Reaction score
84
Fixed a bug. In the divide method, when dividing 0 by a number, it returned a bad value (just a random number in a variable). Now it returns 0.
 

Nestharus

o-o
Reaction score
84
Updated to 1.1.4.8


Removed a few useless local declarations, a few extra sets, and made one strict if statement a bit less strict

Fully commented the code
 

tooltiperror

Super Moderator
Reaction score
231
Official tooltiperror review.

BigInt is a system that is not a revolutionary concept for programming. It has been done for many programming languages that do not support big enough integers. However, BigInt is revolutionary in its own right, as it is the first implementation of a BigInt in JASS, ever I believe.

The code is as well documented as possible. Variables of the type BigInt (herein referred to as BigInts) are already very slow compared to normal Warcraft III integers in arithmetic. Nestharus makes up for this with insane programming concepts, and genius algorithms.

The code, while mainly unreadable, was commented upon and now someone advanced with JASS should be able to understand what a method does at least, and how to modify it.

It's also possible to manipulate BigInts. You can treat it as a stack and push in new digits, and you can perform all four of the basic math operations on it.

There are wide uses for BigInt. I used it personally to make random numbers in combination with [LJASS]SetRandomSeed[/LJASS], [LJASS]StringHash[/LJASS], and [LJASS]GetPlayerName[/LJASS]. Nestharus used it himself for his giant save/load system, Encoder.

This is a high quality resource.

Approved.
 

Nestharus

o-o
Reaction score
84
Fixed a crash in multiplyBig when number being multiplied is 0.

edit
Fixed logical error in multiplyBig
 

Nestharus

o-o
Reaction score
84
Released BigInt 2!!!

Yes, it is finally time...

Division algorithm is much, much faster. When I attempted to do a fast modulo algorithm using Montgomery, it was actually slower than the Division algorithm when working in very large bases like 32768, so I decided to make mod just use division ;o, lol...

The old mod from first BigInt is faster than the current one, but the old one could possibly overflow.


The only things that are op limit safe are those things that crash on their own now. Methods like add and addBig and multiply are no longer op limit safe as they will never crash on their own. What this means is that you have to use them intelligently. If you want to make a method that returns no value op limit safe, simply execute it -> method.execute(args).

Be sure to always work with base 0 -> set i.base = 0. Base 0 is actually base 32768. It is the only non Base object that you may work with. It increases the speed of the system dramatically ; ). If you are working in something like base 10 or base 36, don't come complaining to me about the speed because that's your own problem for working in a stupid base ; P. If you want to output the number in base 10 or 36, change the base after you have done all your operations ;o, lol.


Anyways, enjoy BigInt v2 ;D.


I will start updating my save/load snippets later today as it's 1:30 am atm.

I have thoroughly tested this thing, but if you run into any bugs, let me know.
 

Bribe

vJass errors are legion
Reaction score
67
More like method.evaluate(args) because .execute is like 4-6 times slower ;)
 

Nestharus

o-o
Reaction score
84
method.evaluate doesn't work... it's the same as call method.


edit
nvm, it could be that evaluate only works on methods that return booleans.
 

Nestharus

o-o
Reaction score
84
Fixed bugs with division algorithm
Made division MUCH faster ^^
Made base conversion quite a lot faster
Base conversion still drops a hammer on fps with lots of encryption huge codes ;|
 

Nestharus

o-o
Reaction score
84
The new version is now released..

my magical base conversion algorithm is incredibly fast.. it only needs 1 trigger evaluation as the thread won't crash ^)^. I tested it up to 140 digit very high base numbers, meaning that it is safe to use for any real purposes. Obviously, it will crash on like a 240 digit number, lolz, but a player can only type in 120 characters anyways.

How did I solve the base conversion problem? Rather than converting directly from base to base, I do a very fast conversion to a very large base, then convert to the target large base (not actual base) then do a fast conversion to actual base.

So each conversion works like this
original base -> big base -> big base 2 -> target base

So why the heck are 4 base conversions way the hell faster than 1? The only slow base conversions are those between the 2 big bases, and because the bases are so massive (talking between 1500 and 46340), even these base conversions are fast.

The reason that the base conversions from small -> large -> small are fast is because these conversions convert the base to a higher power. They essentially just group the digits up to make the number smaller. I introduced 2 new methods to do this: pack and unpack. The pack method will pack the number up as much as possible while maintaining safety in the number (no overflow). Unpack will put it back in its normal format.

For example, packing a base 10 number would convert it to base 10000, which is just a matter of combining the digits in groups of 4.

So loop through each group of 4 digits and just combine them... very fast, very easy ; P. Unpacking just goes through each group of digits and takes them apart using modulo. Again, very fast, very easy.

So why does this work? You can group digits up any way you like. Grouping digits up in their own base is the most efficient grouping possible. This is the reason why bases like octal and hexadecimal are so popular, because converting between binary, octal, and hexadecimal, as well as any other power of 2 base, is very fast.

Let's take an example
101110001110

What would that be in hexadecimal?

16 is 2^4, meaning that hexadecimal groups binary up into groups of 4 bits.
1011|1000|1110

So the value would be 1011, 1000, and 1110, which happens to be B8E. You can only do this with bases that are of the same power. For example, 3 could group up into base 9 easily as each base 9 digit is two base 3 digits. Base 10 can go into base 100. Base 60 can go into base 3600, etc, etc. I applied this concept to my base conversion algorithm. Rather than going through tons and tons of division on very massive numbers, I first pack the numbers up into a massive base to minimize the BigInt division as much as possible. Packing is not BigInt division, it is just putting digits together ;o. From there, I do the BigInt division on 2 relatively small numbers, then I unpack the result.

What happens when I convert from something like base 2 to base 4? I can pack base 2 up into base 4 : O. Yes... however, I don't do it ;p. If two bases do share the same packed base, I simply pack the BigInt and then unpack it.

For example, base 2 and base 36 share the same base 32768 for packing. Because of this, converting from base 2 is a simple pack and unpack, no BigInt division necessary ^)^.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I don't see anything in the documentation about HOW big of an 'int' this will allow. Is it arbitrary precision/size?

What's with the lack of any indentation in the code, and the very small amount of comments? This isn't very friendly for anyone to read, and intentionally unfriendly. I doubt you program without any indentation.
 

Nestharus

o-o
Reaction score
84
The code won't fit into the post, lolz... so I had to remove all the spaces D:

If you want to see the code, here it is at THW where it does fit ;p
http://www.hiveworkshop.com/forums/jass-resources-412/system-bigint-188973/


This runs off of arrays, so the max total digits you can have across all BigInts is 8191 =).

The last version did have a bug with division, but I already fixed it + made division way the hell faster o-o.

I decided to do a simple save/load using Scrambler and an encryption strength of 12 o_O. I loaded up a 120 char code and it only did a small freeze >: D. I am just so happy with this lib right now ^)^.
 

Nestharus

o-o
Reaction score
84
Fixed bugs with sizing in deto and popto as well as a couple of bugs in the range deallocations.
 

Nestharus

o-o
Reaction score
84
Fixed a small typo on line 210

sry about the spacing, but it's thehelper's fault since the code can't fit into the post ; \. If the post max char size is increased, I can put up the regular code. If you want the regular code, check THW since it can fit into one post there =).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top