Skip to main content

ApproxEqCairo

Trait ApproxEqCairo 

Source
pub trait ApproxEqCairo: ApproxEq {
    // Required method
    fn approx_eq_cairo(self, other: Self) -> bool;
}
Expand description

Checks whether two floating-point numbers are approximately equal, considering Cairo’s limitations on numeric representation.

Cairo uses fixed-point numbers internally. We implement this trait for f64, so that two numbers can be considered “close enough to equal” if their absolute difference is smaller than the smallest fixed-point fraction that Cairo can represent.

Note that this trait is reliable even if the given numbers are outside of the range that Cairo’s fixed-point numbers can represent. In that case, we check for the absolute difference, and finally allow a difference of 1 unit-in-the-last-place (ULP) for very large f64 values.

Required Methods§

Source

fn approx_eq_cairo(self, other: Self) -> bool

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ApproxEqCairo for f64

Source§

fn approx_eq_cairo(self, other: f64) -> bool

Implementors§