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 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);

Associated Types

type Round[src]

The rounding method.

type Ordering[src]

The direction from rounding.

Loading content...

Required methods

fn assign_round(&mut self, src: Src, round: Self::Round) -> Self::Ordering[src]

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);
Loading content...

Implementors

impl AssignRound<&'_ Constant> for Float[src]

type Round = <Float as AssignRound<Constant>>::Round

type Ordering = <Float as AssignRound<Constant>>::Ordering

impl AssignRound<&'_ Special> for Float[src]

type Round = <Float as AssignRound<Special>>::Round

type Ordering = <Float as AssignRound<Special>>::Ordering

impl AssignRound<&'_ f32> for Float[src]

type Round = <Float as AssignRound<f32>>::Round

type Ordering = <Float as AssignRound<f32>>::Ordering

impl AssignRound<&'_ f64> for Float[src]

type Round = <Float as AssignRound<f64>>::Round

type Ordering = <Float as AssignRound<f64>>::Ordering

impl AssignRound<&'_ i8> for Float[src]

type Round = <Float as AssignRound<i8>>::Round

type Ordering = <Float as AssignRound<i8>>::Ordering

impl AssignRound<&'_ i16> for Float[src]

type Round = <Float as AssignRound<i16>>::Round

type Ordering = <Float as AssignRound<i16>>::Ordering

impl AssignRound<&'_ i32> for Float[src]

type Round = <Float as AssignRound<i32>>::Round

type Ordering = <Float as AssignRound<i32>>::Ordering

impl AssignRound<&'_ i64> for Float[src]

type Round = <Float as AssignRound<i64>>::Round

type Ordering = <Float as AssignRound<i64>>::Ordering

impl AssignRound<&'_ i128> for Float[src]

type Round = <Float as AssignRound<i128>>::Round

type Ordering = <Float as AssignRound<i128>>::Ordering

impl AssignRound<&'_ isize> for Float[src]

type Round = <Float as AssignRound<isize>>::Round

type Ordering = <Float as AssignRound<isize>>::Ordering

impl AssignRound<&'_ u8> for Float[src]

type Round = <Float as AssignRound<u8>>::Round

type Ordering = <Float as AssignRound<u8>>::Ordering

impl AssignRound<&'_ u16> for Float[src]

type Round = <Float as AssignRound<u16>>::Round

type Ordering = <Float as AssignRound<u16>>::Ordering

impl AssignRound<&'_ u32> for Float[src]

type Round = <Float as AssignRound<u32>>::Round

type Ordering = <Float as AssignRound<u32>>::Ordering

impl AssignRound<&'_ u64> for Float[src]

type Round = <Float as AssignRound<u64>>::Round

type Ordering = <Float as AssignRound<u64>>::Ordering

impl AssignRound<&'_ u128> for Float[src]

type Round = <Float as AssignRound<u128>>::Round

type Ordering = <Float as AssignRound<u128>>::Ordering

impl AssignRound<&'_ usize> for Float[src]

type Round = <Float as AssignRound<usize>>::Round

type Ordering = <Float as AssignRound<usize>>::Ordering

impl AssignRound<&'_ Float> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<&'_ Integer> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<Constant> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<Special> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<f32> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<f64> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<i8> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<i16> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<i32> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<i64> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<i128> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<isize> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<u8> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<u16> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<u32> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<u64> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<u128> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<usize> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<Float> for Float[src]

type Round = Round

type Ordering = Ordering

impl AssignRound<Integer> for Float[src]

type Round = Round

type Ordering = Ordering

Loading content...