Trait rug::ops::CompleteRound
source · pub trait CompleteRound {
type Completed;
type Prec;
type Round;
type Ordering;
// Required method
fn complete_round(
self,
prec: Self::Prec,
round: Self::Round
) -> (Self::Completed, Self::Ordering);
// Provided methods
fn complete(self, prec: Self::Prec) -> Self::Completed
where Self: Sized,
Self::Round: Default { ... }
fn complete_round_into<T>(
self,
target: &mut T,
round: Self::Round
) -> Self::Ordering
where Self: Sized,
T: AssignRound<Self, Round = Self::Round, Ordering = Self::Ordering> { ... }
fn complete_into<T>(self, target: &mut T)
where Self: Sized,
Self::Round: Default,
T: AssignRound<Self, Round = Self::Round, Ordering = Self::Ordering> { ... }
}
Expand description
Completes an incomplete-computation value with a specified precision and rounding method.
§Examples
Implementing the trait:
use core::cmp::Ordering;
use rug::float::Round;
use rug::ops::{CompleteRound, Pow};
use rug::Float;
struct LazyPow4<'a>(&'a Float);
impl CompleteRound for LazyPow4<'_> {
type Completed = Float;
type Prec = u32;
type Round = Round;
type Ordering = Ordering;
fn complete_round(self, prec: Self::Prec, round: Self::Round) -> (Float, Ordering) {
Float::with_val_round(prec, self.0.pow(4), round)
}
}
let (val, dir) = LazyPow4(&Float::with_val(53, 3.5)).complete_round(53, Round::Nearest);
assert_eq!(val, 3.5f32.pow(4));
assert_eq!(dir, Ordering::Equal);
Completing an incomplete-computation value:
use core::cmp::Ordering;
use rug::float::Round;
use rug::ops::CompleteRound;
use rug::Float;
let incomplete = Float::u_pow_u(3, 4);
let (complete, dir) = incomplete.complete_round(53, Round::Nearest);
assert_eq!(complete, 81);
assert_eq!(dir, Ordering::Equal);
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn complete(self, prec: Self::Prec) -> Self::Completed
fn complete(self, prec: Self::Prec) -> Self::Completed
Completes the operation with the specified precision and with default rounding.
§Examples
use rug::ops::CompleteRound;
use rug::Float;
let incomplete = Float::u_pow_u(3, 4);
let complete = incomplete.complete(53);
assert_eq!(complete, 81);
sourcefn complete_round_into<T>(
self,
target: &mut T,
round: Self::Round
) -> Self::Ordering
fn complete_round_into<T>( self, target: &mut T, round: Self::Round ) -> Self::Ordering
Completes the operation and stores the result in a target with the specified rounding method.
§Examples
use core::cmp::Ordering;
use rug::float::Round;
use rug::ops::CompleteRound;
use rug::Float;
let mut complete = Float::new(53);
let dir = Float::u_pow_u(3, 4).complete_round_into(&mut complete, Round::Nearest);
assert_eq!(complete, 81);
assert_eq!(dir, Ordering::Equal);
sourcefn complete_into<T>(self, target: &mut T)
fn complete_into<T>(self, target: &mut T)
Completes the operation and stores the result in a target with default rounding.
§Examples
use rug::ops::CompleteRound;
use rug::Float;
let mut complete = Float::new(53);
Float::u_pow_u(3, 4).complete_into(&mut complete);
assert_eq!(complete, 81);