Skip to content

Commit 18b83a5

Browse files
authored
Implement Debug by hand for Interval (#105)
1 parent 9e519ce commit 18b83a5

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/interval.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ pub type Result<T> = result::Result<T, IntervalError>;
4343
/// An interval with [`f64`] bounds.
4444
///
4545
/// It is sometimes referred to as a *bare* interval in contrast to a decorated interval ([`DecInterval`]).
46-
#[derive(Clone, Copy, Debug)]
46+
///
47+
/// Note that, for convenience, the [`Debug`][std::fmt::Debug] output
48+
/// looks like `Interval(a, b)`, where `a` and `b` are the [`f64`]
49+
/// bounds of the interval, although, internally, intervals are not
50+
/// defined as a struct. Empty intervals are written as `Interval(NaN, NaN)`.
51+
#[derive(Clone, Copy)]
4752
#[repr(C)]
4853
pub struct Interval {
4954
// An interval is stored in a SIMD vector in the neginf-sup-nan form:
@@ -55,16 +60,20 @@ pub struct Interval {
5560
//
5661
// Representations of zeros and NaNs are arbitrary; a zero can be either +0.0 or -0.0,
5762
// and a NaN can be either a qNaN or a sNaN with an arbitrary payload.
58-
//
59-
// In Debug formatting, the value of `rep` is printed as either
60-
// `__m128d(-a, b)` (on x86-64) or `float64x2_t(-a, b)` (on AArch64).
6163
pub(crate) rep: F64X2,
6264
}
6365

6466
unsafe impl Send for Interval {}
6567
unsafe impl Sync for Interval {}
6668
impl Unpin for Interval {}
6769

70+
impl fmt::Debug for Interval {
71+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72+
let [a, b] = extract(self.rep);
73+
f.debug_tuple("Interval").field(&-a).field(&b).finish()
74+
}
75+
}
76+
6877
impl Interval {
6978
pub(crate) fn inf_raw(self) -> f64 {
7079
-extract0(self.rep)

0 commit comments

Comments
 (0)