Trait rug::ops::AssignRound [] [src]

pub trait AssignRound<Src = Self> {
    type Round;
    type Ordering;
    fn assign_round(&mut self, src: Src, round: Self::Round) -> Self::Ordering;
}

Assignment with a specified rounding method.

Examples

use rug::float::Round;
use rug::ops::AssignRound;
use std::cmp::Ordering;
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);

Associated Types

The rounding method.

The direction from rounding.

Required Methods

Peforms the assignment.

Examples

use rug::Float;
use rug::float::Round;
use rug::ops::AssignRound;
use std::cmp::Ordering;
// 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);

Implementations on Foreign Types

impl<T> AssignRound<T> for (Float, Ordering) where
    (&'a mut Float, &'b mut Ordering): AssignRound<T, Round = Round, Ordering = Ordering>, 
[src]

[src]

impl<T> AssignRound<T> for (Float, Float) where
    (&'a mut Float, &'b mut Float): AssignRound<T, Round = Round, Ordering = (Ordering, Ordering)>, 
[src]

[src]

impl<T> AssignRound<T> for (Complex, Complex) where
    (&'a mut Complex, &'b mut Complex): AssignRound<T, Round = (Round, Round), Ordering = ((Ordering, Ordering), (Ordering, Ordering))>, 
[src]

[src]

Implementors