Trait SorobanFixedPoint

Source
pub trait SorobanFixedPoint: Sized {
    // Required methods
    fn fixed_mul_floor(&self, env: &Env, y: &Self, denominator: &Self) -> Self;
    fn fixed_mul_ceil(&self, env: &Env, y: &Self, denominator: &Self) -> Self;
    fn fixed_div_floor(&self, env: &Env, y: &Self, denominator: &Self) -> Self;
    fn fixed_div_ceil(&self, env: &Env, y: &Self, denominator: &Self) -> Self;
}
Expand description

Soroban fixed point trait for computing fixed point calculations with Soroban host objects.

Soroban host functions by default are non-recoverable. This means an arithmetic overflow or divide by zero will result in a host panic instead of returning an error. For consistency, this trait will also panic in the same manner.

Required Methods§

Source

fn fixed_mul_floor(&self, env: &Env, y: &Self, denominator: &Self) -> Self

Safely calculates floor(x * y / denominator).

§Panics

This method will panic if the denominator is 0, a phantom overflow occurs, or the result does not fit in Self.

Source

fn fixed_mul_ceil(&self, env: &Env, y: &Self, denominator: &Self) -> Self

Safely calculates ceil(x * y / denominator).

§Panics

This method will panic if the denominator is 0, a phantom overflow occurs, or the result does not fit in Self.

Source

fn fixed_div_floor(&self, env: &Env, y: &Self, denominator: &Self) -> Self

Safely calculates floor(x * denominator / y).

§Panics

This method will panic if the denominator is 0, a phantom overflow occurs, or the result does not fit in Self.

Source

fn fixed_div_ceil(&self, env: &Env, y: &Self, denominator: &Self) -> Self

Safely calculates ceil(x * denominator / y).

§Panics

This method will panic if the denominator is 0, a phantom overflow occurs, or the result does not fit in Self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SorobanFixedPoint for i128

Source§

fn fixed_mul_floor(&self, env: &Env, y: &i128, denominator: &i128) -> i128

Source§

fn fixed_mul_ceil(&self, env: &Env, y: &i128, denominator: &i128) -> i128

Source§

fn fixed_div_floor(&self, env: &Env, y: &i128, denominator: &i128) -> i128

Source§

fn fixed_div_ceil(&self, env: &Env, y: &i128, denominator: &i128) -> i128

Source§

impl SorobanFixedPoint for u128

Source§

fn fixed_mul_floor(&self, env: &Env, y: &u128, denominator: &u128) -> u128

Source§

fn fixed_mul_ceil(&self, env: &Env, y: &u128, denominator: &u128) -> u128

Source§

fn fixed_div_floor(&self, env: &Env, y: &u128, denominator: &u128) -> u128

Source§

fn fixed_div_ceil(&self, env: &Env, y: &u128, denominator: &u128) -> u128

Source§

impl SorobanFixedPoint for I256

Source§

fn fixed_mul_floor(&self, env: &Env, y: &I256, denominator: &I256) -> I256

Source§

fn fixed_mul_ceil(&self, env: &Env, y: &I256, denominator: &I256) -> I256

Source§

fn fixed_div_floor(&self, env: &Env, y: &I256, denominator: &I256) -> I256

Source§

fn fixed_div_ceil(&self, env: &Env, y: &I256, denominator: &I256) -> I256

Source§

impl SorobanFixedPoint for U256

Source§

fn fixed_mul_floor(&self, _env: &Env, y: &U256, denominator: &U256) -> U256

Source§

fn fixed_mul_ceil(&self, env: &Env, y: &U256, denominator: &U256) -> U256

Source§

fn fixed_div_floor(&self, _env: &Env, y: &U256, denominator: &U256) -> U256

Source§

fn fixed_div_ceil(&self, env: &Env, y: &U256, denominator: &U256) -> U256

Implementors§