Skip to content

Commit

Permalink
tweak RTO result
Browse files Browse the repository at this point in the history
  • Loading branch information
bksaiki committed Oct 9, 2023
1 parent 357d835 commit fe343fd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
7 changes: 6 additions & 1 deletion src/fixed/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ rounded_1ary_impl!(RoundedAbs, format_abs, abs, mpfr_abs);
rounded_1ary_impl!(RoundedSqrt, format_sqrt, sqrt, mpfr_sqrt);
rounded_1ary_impl!(RoundedCbrt, format_cbrt, cbrt, mpfr_cbrt);
rounded_1ary_impl!(RoundedRecip, format_recip, recip, mpfr_recip);
rounded_1ary_impl!(RoundedRecipSqrt, format_recip_sqrt, recip_sqrt, mpfr_recip_sqrt);
rounded_1ary_impl!(
RoundedRecipSqrt,
format_recip_sqrt,
recip_sqrt,
mpfr_recip_sqrt
);
rounded_1ary_impl!(RoundedExp, format_exp, exp, mpfr_exp);
rounded_1ary_impl!(RoundedExp2, format_exp2, exp2, mpfr_exp2);
rounded_1ary_impl!(RoundedLog, format_log, log, mpfr_log);
Expand Down
7 changes: 6 additions & 1 deletion src/float/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ rounded_1ary_impl!(RoundedAbs, format_abs, abs, mpfr_abs);
rounded_1ary_impl!(RoundedSqrt, format_sqrt, sqrt, mpfr_sqrt);
rounded_1ary_impl!(RoundedCbrt, format_cbrt, cbrt, mpfr_cbrt);
rounded_1ary_impl!(RoundedRecip, format_recip, recip, mpfr_recip);
rounded_1ary_impl!(RoundedRecipSqrt, format_recip_sqrt, recip_sqrt, mpfr_recip_sqrt);
rounded_1ary_impl!(
RoundedRecipSqrt,
format_recip_sqrt,
recip_sqrt,
mpfr_recip_sqrt
);
rounded_1ary_impl!(RoundedExp, format_exp, exp, mpfr_exp);
rounded_1ary_impl!(RoundedExp2, format_exp2, exp2, mpfr_exp2);
rounded_1ary_impl!(RoundedLog, format_log, log, mpfr_log);
Expand Down
7 changes: 6 additions & 1 deletion src/ieee754/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ rounded_1ary_impl!(RoundedAbs, format_abs, abs, mpfr_abs);
rounded_1ary_impl!(RoundedSqrt, format_sqrt, sqrt, mpfr_sqrt);
rounded_1ary_impl!(RoundedCbrt, format_cbrt, cbrt, mpfr_cbrt);
rounded_1ary_impl!(RoundedRecip, format_recip, recip, mpfr_recip);
rounded_1ary_impl!(RoundedRecipSqrt, format_recip_sqrt, recip_sqrt, mpfr_recip_sqrt);
rounded_1ary_impl!(
RoundedRecipSqrt,
format_recip_sqrt,
recip_sqrt,
mpfr_recip_sqrt
);
rounded_1ary_impl!(RoundedExp, format_exp, exp, mpfr_exp);
rounded_1ary_impl!(RoundedExp2, format_exp2, exp2, mpfr_exp2);
rounded_1ary_impl!(RoundedLog, format_log, log, mpfr_log);
Expand Down
33 changes: 15 additions & 18 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ pub struct RTOResult {
}

impl RTOResult {
/// Constructs an [`RTOResult`] from an MPFR result.
pub fn new(val: Float, t: i32, flags: MPFRFlags, prec: usize) -> Self {
Self {
num: RFloat::from(val).with_ternary(t),
prec,
flags,
}
}

/// The numerical result of an operation.
pub fn num(&self) -> &RFloat {
&self.num
Expand Down Expand Up @@ -87,12 +96,8 @@ macro_rules! mpfr_1ary {
(t, mpfr_flags())
};

// apply correction to get the last bit and compose
RTOResult {
num: RFloat::from(dst).with_ternary(t),
prec: p,
flags,
}
// compose result
RTOResult::new(dst, t, flags, p)
}
};
}
Expand Down Expand Up @@ -126,12 +131,8 @@ macro_rules! mpfr_2ary {
(t, mpfr_flags())
};

// apply correction to get the last bit and compose
RTOResult {
num: RFloat::from(dst).with_ternary(t),
prec: p,
flags,
}
// compose result
RTOResult::new(dst, t, flags, p)
}
};
}
Expand Down Expand Up @@ -167,12 +168,8 @@ macro_rules! mpfr_3ary {
(t, mpfr_flags())
};

// apply correction to get the last bit and compose
RTOResult {
num: RFloat::from(dst).with_ternary(t),
prec: p,
flags,
}
// compose result
RTOResult::new(dst, t, flags, p)
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/rfloat/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl RFloatContext {
}

/// Clears the maximum allowable precision.
pub fn without_max_precision(mut self) -> Self {
pub fn without_max_p(mut self) -> Self {
self.max_p = None;
self
}
Expand Down

0 comments on commit fe343fd

Please sign in to comment.