[][src]Trait rug::ops::RemFromRound

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

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

type Round

The rounding method.

type Ordering

The direction from rounding.

Loading content...

Required methods

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

Implementors

impl RemFromRound<f32> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<f64> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<i8> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<i16> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<i32> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<i64> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<i128> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<u8> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<u16> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<u32> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<u64> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<u128> for Float[src]

type Round = Round

type Ordering = Ordering

impl RemFromRound<Float> for Float[src]

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

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

type Round = Round

type Ordering = Ordering

Loading content...