Fixed Point Roll
A set of functions to operate over u64 numbers with 1e9 precision.
Interface
roll
It returns 1 ROLL - 1_000_000_000.
@return u64. 1e9
try_mul_down
It tries to x
* y
/ 1_000_000_000 rounding down. It returns zero instead of throwing an overflow error.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u64. The result of
x
*y
/ 1_000_000_000.
try_mul_up
It tries to x
* y
/ 1_000_000_000 rounding up. It returns zero instead of throwing an overflow error.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u64. The result of
x
*y
/ 1_000_000_000.
try_div_down
It tries to x
* 1_000_000_000 / y
rounding down. It returns zero instead of throwing an overflow error.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u64. The result of
x
* 1_000_000_000 /y
.
try_div_up
It tries to x
* 1_000_000_000 / y
rounding up. It returns zero instead of throwing an overflow error.
@param x: The first operand.
@param y: The second operand.
@return bool. If the operation was successful.
@return u64. The result of
x
* 1_000_000_000 /y
.
mul_down
x
* y
/ 1_000_000_000 rounding down.
@param x: The first operand.
@param y: The second operand.
@return u64. The result of
x
*y
/ 1_000_000_000.
Aborts
On overflow. If the result is over the maximum u256 number.
mul_up
x
* y
/ 1_000_000_000 rounding up.
@param x: The first operand.
@param y: The second operand.
@return u64. The result of
x
*y
/ 1_000_000_000.
Aborts
On overflow. If the result is over the maximum u256 number.
div_down
x
* 1_000_000_000 / y
rounding down.
@param x: The first operand.
@param y: The second operand.
@return u64. The result of
x
* 1_000_000_000 /y
.
Aborts
On zero division.
div_up
x
* 1_000_000_000 / y
rounding up.
@param x: The first operand.
@param y: The second operand.
@return u64. The result of
x
* 1_000_000_000 /y
.
Aborts
On zero division.
to_roll
It converts x
precision to a ROLL
, a number with a precision of 1e9.
@param x: The value to be converted.
@param decimal_factor: The current decimal scalar of x.
@return u64. The result of
x
* 1_000_000_000 /y
.
Aborts
decimal_factor is zero.
Last updated