Trait rug::ops::AssignRound
source · [−]pub trait AssignRound<Src = Self> {
type Round;
type Ordering;
fn assign_round(&mut self, src: Src, round: Self::Round) -> Self::Ordering;
}
Expand description
Assignment with a specified rounding method.
Examples
use core::cmp::Ordering;
use rug::{float::Round, ops::AssignRound};
struct F(f64);
impl AssignRound<f64> for F {
type Round = Round;
type Ordering = Ordering;
fn assign_round(&mut self, rhs: f64, _round: Round) -> Ordering {
self.0 = rhs;
Ordering::Equal
}
}
let mut f = F(3.0);
let dir = f.assign_round(5.0, Round::Nearest);
assert_eq!(f.0, 5.0);
assert_eq!(dir, Ordering::Equal);
Required Associated Types
Required Methods
fn assign_round(&mut self, src: Src, round: Self::Round) -> Self::Ordering
fn assign_round(&mut self, src: Src, round: Self::Round) -> Self::Ordering
Peforms the assignment.
Examples
use core::cmp::Ordering;
use rug::{float::Round, ops::AssignRound, Float};
// only four significant bits
let mut f = Float::new(4);
let dir = f.assign_round(3.3, Round::Nearest);
// 3.3 rounded down to 3.25
assert_eq!(f, 3.25);
assert_eq!(dir, Ordering::Less);
let dir = f.assign_round(3.3, Round::Up);
// 3.3 rounded up to 3.5
assert_eq!(f, 3.5);
assert_eq!(dir, Ordering::Greater);