Author Topic: Anyone have experience with Ipquarx's BLMathLib?  (Read 2005 times)

Does this library work?
https://github.com/Ipdude/BLMathLib

If it does, can someone explain to me how to use some of the basic math operations? I can't get f_add(%num1, %num2) to return anything useful. Echoing it's result just gives me a global variable name, and that variable always contains 0.
« Last Edit: May 29, 2020, 09:23:14 PM by Crook »

f_add doesn't return anything, its a mutator. after calling it you have to actually get the result yourself. i dont know how it works but it should be something like $n[number,index] i think? the parameters for f_add are supposedly array pointers
« Last Edit: May 29, 2020, 09:55:48 PM by PhantOS »

Here's the basics on how to use it.

First, you have to create a reference to a number. use
Code: [Select]
%reference = f_makenum("hexadecimal_here"); to create a reference to a number. The hexadecimal will be put into the number, so if you do
Code: [Select]
%reference = f_makenum("1234"); it'll give you a reference to a number that contains the decimal value 4660.

Then, to add two numbers, send the f_add, f_sub, etc functions two number references (they have to be different!)
Code: [Select]
f_add(%ref1, %ref2); (notice i'm not using the return value) will add the values %ref1 and %ref2 refer to, and place the result in %ref1.

Seems like a long and complicated way to do something simple.

What advantages does this system provide? Right off the bat it looks like it can keep a history of every number that you use in a sequence of operations, at the downside of some added tedium.

What advantages does this system provide? Right off the bat it looks like it can keep a history of every number that you use in a sequence of operations, at the downside of some added tedium.
I came across it looking for a torquescript bignum library, which would allow arbitrary-precision arithmetic. I was using it for a gamemode where you could have money and go above $1 million without it becoming inaccurate/compressed to scientific notation

I ended up using code from this add-on: https://github.com/Tungul/Support_Cryptography
It's pretty simple you can just add two numbers together with IMath_Add but there are a couple other similar functions and I'm not sure what they all do lol
« Last Edit: June 24, 2020, 11:32:01 AM by Crook »

what are you doing that requires integers over one million? if any int is indeed exceeding one million in value then the increments on that int are way too big.

im not trying to sidetrack or derail your solution, i just think that the problem can be solved with a change in design rather than an entire library

What advantages does this system provide? Right off the bat it looks like it can keep a history of every number that you use in a sequence of operations, at the downside of some added tedium.
(my guess) the functions do bitwise operations which may be significantly faster than torque's + - operators. it appears to be a tradeoff between more memory and less cpu usage. it only seems really applicable in scripts that use heavy iteration/recursion like pathfinding or procedural routines where you're dealing with linear or exponential complexity and you want to squeeze as much performance as possible out of the routine. if you only need to add/subtract at arbitrary times like when you hit a button or fire a gun then it might not be worth using at all as the performance gains will be almost unnoticeable
« Last Edit: June 25, 2020, 12:58:55 PM by PhantOS »

I've been on and off building a zombie gamemode that incorporates a lot of CRPG elements, particularly money and buying/selling items. The last time I got to +1 million in a CRPG some things broke and I was able to pull money out of thin air by abusing the inaccuracy. I'm not far long enough to know how feasible it is to actually get that much money but job progression is effectively infinite and scales exponentially

I've been on and off building a zombie gamemode that incorporates a lot of CRPG elements, particularly money and buying/selling items. The last time I got to +1 million in a CRPG some things broke and I was able to pull money out of thin air by abusing the inaccuracy. I'm not far long enough to know how feasible it is to actually get that much money but job progression is effectively infinite and scales exponentially
if you explicitly want it to be infinite and scale exponentially, then yea its a good idea to use arbitrary precision. one thing worth doing in conjunction is factoring out everything with the smallest source of money gain/loss. ie:

one zombie kill - rewards 10 points (change to 1 point)
op gun - costs 100000 points (change to 10000)

or lower the rate of exponential gain / set a cap to money. a bignum library will inevitably require more memory allocation and more processing (albeit very small and likely unnoticeable) but most importantly it adds extra complexity to your project to have to introduce static typing in a weakly typed language. in theory the only time you'll ever need bignum libraries is if you're making a program that absolutely requires the precision of big numbers, like a space simulation. a CRPG doesn't require big numbers, it's just a very common theme for them to incorporate unnecessarily large multiples of numbers and unmanaged accumulation of wealth

tldr: bignum will not make your game better or worse, but will make working on the game objectively harder. refactor first before trying to meet excessive/unnecessary scope demands
« Last Edit: June 25, 2020, 01:19:09 PM by PhantOS »

Seems like a long and complicated way to do something simple.
It's almost identical to the way that the GNU GMP library handles it. That's the most popular bignum library in existence.

I came across it looking for a torquescript bignum library, which would allow arbitrary-precision arithmetic. I was using it for a gamemode where you could have money and go above $1 million without it becoming inaccurate/compressed to scientific notation

I ended up using code from this add-on: https://github.com/Tungul/Support_Cryptography
It's pretty simple you can just add two numbers together with IMath_Add but there are a couple other similar functions and I'm not sure what they all do lol
I totally understand why you'd wanna use that old code of mine since it's base 10 so you can actually display the numbers (which is kinda vital). it's about an order of magnitude slower though. you may have problems if your server is *constantly* doing math with it.