Math256
Structs
Constants
Interface
try_add
It tries to perform x
+ y
. Checks for overflow.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u256. The result of
x
+y
. If it fails, it will be 0.
try_sub
It tries to perform x
- y
. Checks for underflow.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u256. The result of
x
-y
. If it fails, it will be 0.
try_mul
It tries to perform x
* y
.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u256. The result of
x
*y
. If it fails, it will be 0.
try_div_down
It tries to perform x
/ y rounding down.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u256. The result of x / y. If it fails, it will be 0.
try_div_up
It tries to perform x
/ y rounding up.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u256. The result of
x
/y
. If it fails, it will be 0.
try_mul_div_down
It tries to perform x
* y
/ z
rounding down. Checks for zero division and overflow.
@param x: The first operand.
@param y: The second operand.
@param z: The divisor.
@return bool. If the operation was successful.
@return u256. The result of
x
*y
/z
. If it fails, it will be 0.
try_mul_div_up
It tries to perform x
* y
/ z
rounding up.
@param x: The first operand.
@param y: The second operand.
@param z: The divisor.
@return bool. If the operation was successful.
@return u256. The result of
x
*y
/z
. If it fails, it will be 0.
try_mod
It tries to perform x
% y
.
@param x: The first operand.
@param y: The second operand.
@param z: The divisor.
@return bool. If the operation was successful.
@return u256. The result of
x
%y
. If it fails, it will be 0.
mul
It performs x
* y
.
@param x: The first operand.
@param y: The second operand.
@return u256. The result of
x
*y
.
div_down
It performs x
/ y
rounding down.
@param x: The first operand.
@param y: The second operand.
@return u256. The result of
x
/y
.
Abort
It will throw on zero division.
div_up
It performs x
/ y
rounding up.
@param x: The first operand.
@param y: The second operand.
@return u256. The result of
x
/y
.
Abort
It will throw on zero division.
mul_div_down
It performs x
* y
/ z
rounding down.
@param x: The first operand.
@param y: The second operand.
@param z: The divisor
@return u256. The result of
x
*y
/z
.
mul_div_up
It performs x
* y
/ z
rounding up.
@param x: The first operand.
@param y: The second operand.
@param z: The divisor
@return u256. The result of
x
*y
/z
.
min
It returns the lowest number.
@param x: The first operand.
@param y: The second operand.
@return u256. The lowest number.
max
It returns the largest number.
@param x: The first operand.
@param y: The second operand.
@return u256. The largest number.
clamp
Clamps x
between the range of [lower, upper]
@param x: The first operand.
@param y: The second operand.
@return u256. The clamped x.
diff
Performs |x - y|.
@param x: The first operand.
@param y: The second operand.
@return u256. The difference.
pow
Performs n^e.
@param n: The base.
@param e: The exponent.
@return u256. The result of n^e.
sum
Adds all x in nums
in a vector.
@param nums: A vector of numbers.
@return u256. The sum.
average
It returns the average between two numbers (x
+ y
) / 2.
It does not overflow.
@param x: The first operand.
@param y: The second operand.
@return u256. (
x
+y
) / 2.
average_vector
Calculates the average of the vector of numbers sum of vector/length of vector.
@param nums: A vector of numbers.
@return u256. The average.
sqrt_down
Returns the square root of x
number. If the number is not a perfect square, the x is rounded down.
@param a: The operand.
@return u256. The square root of x rounding down.
sqrt_up
Returns the square root of x
number. If the number is not a perfect square, the x
is rounded up.
@param a: The operand.
@return u256. The square root of x rounding up.
log2_down
Returns the log2(x) rounding down.
@param x: The operand.
@return u8. Log2(x).
log2_up
Returns the log2(x) rounding up.
@param x: The operand.
@return u16. Log2(x).
log10_down
Returns the log10(x) rounding down.
@param x: The operand.
@return u8. Log10(x)
log10_up
Returns the log10(x) rounding up.
@param x: The operand.
@return u8. Log10(x)
log256_down
Returns the log256(x) rounding down.
@param x: The operand.
@return u8. Log256(x).
log256_up
Returns the log256(x) rounding up.
@param x: The operand.
@return u8. Log256(x).
Last updated