logo
pub trait RemFromRound<Lhs = Self> {
    type Round;
    type Ordering;
    fn rem_from_round(&mut self, lhs: Lhs, round: Self::Round) -> Self::Ordering;
}
Expand description

Compound remainder operation and assignment to the rhs operand with a specified rounding method.

Examples

use core::cmp::Ordering;
use rug::{
    float::Round,
    ops::{RemAssignRound, RemFromRound},
    Float,
};
struct F(f64);
impl RemFromRound<f64> for F {
    type Round = Round;
    type Ordering = Ordering;
    fn rem_from_round(&mut self, lhs: f64, round: Round) -> Ordering {
        let mut f = Float::with_val(53, lhs);
        let dir = f.rem_assign_round(self.0, round);
        self.0 = f.to_f64();
        dir
    }
}
let mut f = F(1.25);
let dir = f.rem_from_round(3.25, Round::Nearest);
// 3.25 % 1.25 = 0.75
assert_eq!(f.0, 0.75);
assert_eq!(dir, Ordering::Equal);

Associated Types

The rounding method.

The direction from rounding.

Required methods

Performs the remainder operation.

Examples
use core::cmp::Ordering;
use rug::{float::Round, ops::RemFromRound, Float};
// only four significant bits
let mut f = Float::with_val(4, 32);
let dir = f.rem_from_round(17, Round::Nearest);
// 17 rounded down to 16
assert_eq!(f, 16);
assert_eq!(dir, Ordering::Less);

Implementors