assert_close_to

Function assert_close_to 

Source
pub fn assert_close_to<T: Float + Display + Copy, U: Display + Into<T> + Copy>(
    left: T,
    right: U,
    precision: i32,
)
Expand description

Ensures that two decimals are equal with the specified precision. In case of panic, the function outputs the value of the decimal along with a debug expression.

2つの小数が指定した精度で等しいことを保証する。 パニックになると、この関数は小数の値をデバッグ表現とともに出力する。

§Examples

use close_to::assert_close_to;

assert_close_to(1.0, 1.0001, 3);
use close_to::assert_close_to;

assert_close_to(1.0, 1.0001, 4); // panic with the following message

// assertion 'left ≈ right` failed
// left:  1
// right: 1.0001
// received_diff: 0.00009999999999998899
// expected_diff: 0.00005