Skip to content

Commit

Permalink
Implement Debug by hand for Interval (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris00 authored Aug 23, 2024
1 parent 9e519ce commit 18b83a5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ pub type Result<T> = result::Result<T, IntervalError>;
/// An interval with [`f64`] bounds.
///
/// It is sometimes referred to as a *bare* interval in contrast to a decorated interval ([`DecInterval`]).
#[derive(Clone, Copy, Debug)]
///
/// Note that, for convenience, the [`Debug`][std::fmt::Debug] output
/// looks like `Interval(a, b)`, where `a` and `b` are the [`f64`]
/// bounds of the interval, although, internally, intervals are not
/// defined as a struct. Empty intervals are written as `Interval(NaN, NaN)`.
#[derive(Clone, Copy)]
#[repr(C)]
pub struct Interval {
// An interval is stored in a SIMD vector in the neginf-sup-nan form:
Expand All @@ -55,16 +60,20 @@ pub struct Interval {
//
// Representations of zeros and NaNs are arbitrary; a zero can be either +0.0 or -0.0,
// and a NaN can be either a qNaN or a sNaN with an arbitrary payload.
//
// In Debug formatting, the value of `rep` is printed as either
// `__m128d(-a, b)` (on x86-64) or `float64x2_t(-a, b)` (on AArch64).
pub(crate) rep: F64X2,
}

unsafe impl Send for Interval {}
unsafe impl Sync for Interval {}
impl Unpin for Interval {}

impl fmt::Debug for Interval {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let [a, b] = extract(self.rep);
f.debug_tuple("Interval").field(&-a).field(&b).finish()
}
}

impl Interval {
pub(crate) fn inf_raw(self) -> f64 {
-extract0(self.rep)
Expand Down

0 comments on commit 18b83a5

Please sign in to comment.