CloseTo

Trait CloseTo 

Source
pub trait CloseTo<T, U: Into<T>> {
    // Required methods
    fn close_to(&self, other: U, precision: i32) -> (bool, T, T);
    fn far_from(&self, other: U, precision: i32) -> (bool, T, T);
}
Expand description

Trait to determine if two decimals are equal to a specified precision. Implemented in float type by default.

2つの小数が指定した精度で等しいかどうかを判定するトレイト。 デフォルトでfloat型に実装されている。

§Examples

use close_to::CloseTo;

let (is_close, ..) = 1.0.close_to(1.0001, 3);
assert!(is_close);

assert!(1.0.far_from(1.0001, 4).0);

Required Methods§

Source

fn close_to(&self, other: U, precision: i32) -> (bool, T, T)

Determine if two decimals are equal with the specified precision.

2つの小数が指定した精度で等しいかどうかを判定する。

Source

fn far_from(&self, other: U, precision: i32) -> (bool, T, T)

Determine if two decimals are not equal with the specified precision.

2つの小数が指定した精度で等しくないかどうかを判定する。

Implementors§

Source§

impl<T: Float, U: Into<T>> CloseTo<T, U> for T