Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 9612576

Browse files
committed
Print the hex float format upon failure
Now that we have a hex float formatter, make use of it for test output. This produces values that are easier to read than the bitwise hex representation. Example: thread 'mp_quickspace_fmaf128' panicked at crates/libm-test/tests/multiprecision.rs:17:48: called `Result::unwrap()` on an `Err` value: input: (0xe38d71c71c71c71c71c71c71c71c71c8, 0xe38d71c71c71c71c71c71c71c71c71c8, 0xffff0000000000000000000000000000) as hex: (-0x1.71c71c71c71c71c71c71c71c71c8p+9102, -0x1.71c71c71c71c71c71c71c71c71c8p+9102, -inf) as bits: (0xe38d71c71c71c71c71c71c71c71c71c8, 0xe38d71c71c71c71c71c71c71c71c71c8, 0xffff0000000000000000000000000000) expected: 0xffff0000000000000000000000000000 -inf 0xffff0000000000000000000000000000 actual: 0x7fff8000000000000000000000000000 NaN 0x7fff8000000000000000000000000000 Caused by: real value != NaN
1 parent fd7592e commit 9612576

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

crates/libm-test/src/test_traits.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use std::fmt;
1010

1111
use anyhow::{Context, anyhow, bail, ensure};
12+
use libm::support::Hexf;
1213

1314
use crate::precision::CheckAction;
1415
use crate::{CheckCtx, Float, Int, MaybeOverride, SpecialCase, TestResult};
@@ -35,7 +36,10 @@ pub trait CheckOutput<Input>: Sized {
3536
///
3637
/// This is only used for printing errors so allocating is okay.
3738
pub trait Hex: Copy {
39+
/// Hex integer syntax.
3840
fn hex(self) -> String;
41+
/// Hex float syntax.
42+
fn hexf(self) -> String;
3943
}
4044

4145
/* implement `TupleCall` */
@@ -128,6 +132,10 @@ where
128132
fn hex(self) -> String {
129133
format!("({},)", self.0.hex())
130134
}
135+
136+
fn hexf(self) -> String {
137+
format!("({},)", self.0.hexf())
138+
}
131139
}
132140

133141
impl<T1, T2> Hex for (T1, T2)
@@ -138,6 +146,10 @@ where
138146
fn hex(self) -> String {
139147
format!("({}, {})", self.0.hex(), self.1.hex())
140148
}
149+
150+
fn hexf(self) -> String {
151+
format!("({}, {})", self.0.hexf(), self.1.hexf())
152+
}
141153
}
142154

143155
impl<T1, T2, T3> Hex for (T1, T2, T3)
@@ -149,6 +161,10 @@ where
149161
fn hex(self) -> String {
150162
format!("({}, {}, {})", self.0.hex(), self.1.hex(), self.2.hex())
151163
}
164+
165+
fn hexf(self) -> String {
166+
format!("({}, {}, {})", self.0.hexf(), self.1.hexf(), self.2.hexf())
167+
}
152168
}
153169

154170
/* trait implementations for ints */
@@ -160,6 +176,10 @@ macro_rules! impl_int {
160176
fn hex(self) -> String {
161177
format!("{self:#0width$x}", width = ((Self::BITS / 4) + 2) as usize)
162178
}
179+
180+
fn hexf(self) -> String {
181+
String::new()
182+
}
163183
}
164184

165185
impl<Input> $crate::CheckOutput<Input> for $ty
@@ -234,6 +254,10 @@ macro_rules! impl_float {
234254
width = ((Self::BITS / 4) + 2) as usize
235255
)
236256
}
257+
258+
fn hexf(self) -> String {
259+
format!("{}", Hexf(self))
260+
}
237261
}
238262

239263
impl<Input> $crate::CheckOutput<Input> for $ty
@@ -324,13 +348,18 @@ where
324348
res.with_context(|| {
325349
format!(
326350
"\
327-
\n input: {input:?} {ibits}\
328-
\n expected: {expected:<22?} {expbits}\
329-
\n actual: {actual:<22?} {actbits}\
351+
\n input: {input:?}\
352+
\n as hex: {ihex}\
353+
\n as bits: {ibits}\
354+
\n expected: {expected:<22?} {exphex} {expbits}\
355+
\n actual: {actual:<22?} {acthex} {actbits}\
330356
",
331-
actbits = actual.hex(),
332-
expbits = expected.hex(),
357+
ihex = input.hexf(),
333358
ibits = input.hex(),
359+
exphex = expected.hexf(),
360+
expbits = expected.hex(),
361+
actbits = actual.hex(),
362+
acthex = actual.hexf(),
334363
)
335364
})
336365
}
@@ -365,12 +394,15 @@ macro_rules! impl_tuples {
365394
.with_context(|| format!(
366395
"full context:\
367396
\n input: {input:?} {ibits}\
397+
\n as hex: {ihex}\
398+
\n as bits: {ibits}\
368399
\n expected: {expected:?} {expbits}\
369400
\n actual: {self:?} {actbits}\
370401
",
371-
actbits = self.hex(),
372-
expbits = expected.hex(),
402+
ihex = input.hexf(),
373403
ibits = input.hex(),
404+
expbits = expected.hex(),
405+
actbits = self.hex(),
374406
))
375407
}
376408
}

0 commit comments

Comments
 (0)