Trait rug::ops::RemFromRound
source · pub trait RemFromRound<Lhs = Self> {
type Round;
type Ordering;
// Required method
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;
use rug::ops::{RemAssignRound, RemFromRound};
use rug::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);
Required Associated Types§
Required Methods§
sourcefn rem_from_round(&mut self, lhs: Lhs, round: Self::Round) -> Self::Ordering
fn rem_from_round(&mut self, lhs: Lhs, round: Self::Round) -> Self::Ordering
Performs the remainder operation.
§Examples
use core::cmp::Ordering;
use rug::float::Round;
use rug::ops::RemFromRound;
use rug::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);