[Include] Numlib - Math library for huge numbers (larger than 32-bits)
#1

Numlib

THIS LIBRARY IS NO LONGER MAINTAINED.

The source code is available here.

What is this and why would I use it?
Numlib is a SA-MP library for dealing with numbers greater than 2 147 483 647,
which means numbers greater than 32-bit numbers. The library allows you to
perform basic mathematical operations (add and subtract at the moment) with
integers in form of strings, which is the reason why this library is able to
handle almost any numbers.

So if you need to deal with big numbers, greater than one billion, this library
might be useful for you.

Functions

add:
Код:
Add two integers
	
	Parameters:
		number1[]	An integer represented as a char array
		number2[]	An integer represented as a char array
	
	Returns:
		The sum of number1 and number2 as a char array
subtract:
Код:
Subtract two integers
	
	Parameters:
		number1[]	An integer represented as a char array
		number2[]	An integer represented as a char array
	
	Returns:
		The remainder of substraction of number1 and number2 as a char array
multiply
Код:
Multiply two numbers

	Parameters:
		number1[]	An integer represented as a char array
		number2[]	An integer represented as a char array

	Returns:
		The result of the multiplication as a char array
num_power
Код:
Raise number (char array) to the power of another number (32-bit integer)

	Parameters:
		number1[]	An integer represented as a char array
		power		A 32-bit integer
		
	Returns:
		The result of the power as a char array
divide
Код:
Divide a number (char array) by another number (32-bit integer)

	Parameters:
		divident[]	An integer represented as a char array
		divisor		A 32-bit integer
		
	Returns:
		The result of the division as a char array. The result is always an integer, and the remainder can be obtained using get_remainder function.
get_remainder
Код:
Get the remainder of a division. Works similarly to modulus (%).

	Parameters:
		divident[]	An integer represented as a char array
		divisor		A 32-bit integer
		
	Returns:
		The remainder of the division as a 32-bit integer
is_greater
Код:
Compares two char arrays (as if they were numbers) and determines whether the first one is greater than the second or not
	
	Parameters:
		number1[]	An integer represented as a char array
		number2[]	An integer represented as a char array
	
	Returns:
		boolean: true or false
is_less
Код:
Compares two char arrays (as if they were numbers) and determines whether the first one is smaller than the second or not
	
	Parameters:
		number1[]	An integer represented as a char array
		number2[]	An integer represented as a char array
	
	Returns:
		boolean: true or false
Example
pawn Код:
new integer1[20], integer2[20];

integer1 = "1000000000000000000";
integer2 = "5320010493843209492";

printf("Result: %s", add(integer1, integer2));

// Output: Result: 6320010493843209492
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)