Posted 14 April 2013 - 12:10 PM
Hello all.
This API allows programmers to use unsigned integers of effectively any size (as long as you have enough memory to hold it). Most programmers won't need to use this (2 to the power of 32 is usually big enough), but if you're coding something involving cryptography (such as a hash function), then you may want to use this.
This API stores arbitrary precision integers (or "bigints") as tables, with each digit in the number taking up one entry in the table. For example, the number 1273 would be stored as:
In addition, instead of using the normal operators ("+", "-", ">=", etc.), you will have to use the included functions.
Keep in mind:
This API allows programmers to use unsigned integers of effectively any size (as long as you have enough memory to hold it). Most programmers won't need to use this (2 to the power of 32 is usually big enough), but if you're coding something involving cryptography (such as a hash function), then you may want to use this.
This API stores arbitrary precision integers (or "bigints") as tables, with each digit in the number taking up one entry in the table. For example, the number 1273 would be stored as:
{3,7,2,1}
In addition, instead of using the normal operators ("+", "-", ">=", etc.), you will have to use the included functions.
Keep in mind:
- Bigints are unsigned (cannot be negative). Operations where the result should be less than zero will have an undefined result.
- You cannot pass bigints to a function that accepts "normal" numbers. (i.e you cannot pass a bigint to math.sqrt().)
- This API supports basic arithmetic (add, sub, mul, div, mod, exp), comparisons, and bitwise operations.
- Bitwise NOT may not return the value you expect; it only inverts the values that correspond to the value itself. For example,
would return 130 instead of -127.bigInt.bnot({6,2,1})
- Left and right shifts: blshift() and brshift() instead of bitwiseLeftShift() and bitwiseRightShift().
- sub, mul, div, mod, exp: subtract(), multiply(), divide(), modulo(), exponent() instead of sub(), mul(), div(), mod(), and exp().
- <the comparison functions>: cmp_<full name of comparision> (e.g "cmp_greater_than_or_equal_to", "cmp_greater_than_equal_to", and "cmp_gteq" are equivalent)
- bitwise operations (AND, OR, XOR, NOT): band(), bor(), bxor(), bnot() instead of bitwiseNOT(), bitwiseOR(), bitwiseAND(), and bitwiseXOR().