Skip to content

Commit 64befb6

Browse files
drinkcatsylvestre
authored andcommitted
test_od: Add f128 test (actually a f80 test)
1 parent 8935a61 commit 64befb6

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

tests/by-util/test_od.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,87 @@ fn test_f64() {
309309
.stdout_only(expected_output);
310310
}
311311

312+
#[test]
313+
fn test_f128() {
314+
// This actually tests f80 parsing (x86(-64) behavior.
315+
// Top 48-bits are ignored, padded with semi-random values here
316+
let input: [u8; 19 * 16] = [
317+
// Examples from Wikipedia: https://en.wikipedia.org/wiki/Extended_precision
318+
// ... m ....................................] [exp+sign] [ padding (48 bits) .....
319+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
320+
0xcf, // 3.64519953188247460252841 × 10^−4951 (smallest positive subnormal number)
321+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
322+
0xca, // 3.36210314311209350589816 × 10^−4932 (largest subnormal number)
323+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
324+
0xca, // 3.36210314311209350626268 × 10^−4932 (smallest positive normal number)
325+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
326+
0xca, // 1.18973149535723176502126 × 10^4932 (largest normal number)
327+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
328+
0xca, // 0.99999999999999999994579 (largest number less than one)
329+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
330+
0xca, // 1 (one)
331+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
332+
0xca, // 1.00000000000000000010842 (smallest number larger than one)
333+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x40, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
334+
0xca, // 2
335+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xc0, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
336+
0xca, // -2
337+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
338+
0xca, // 0
339+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
340+
0xca, // -0
341+
0x35, 0xc2, 0x68, 0x21, 0xa2, 0xda, 0x0f, 0xc9, 0x00, 0x40, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
342+
0xca, //3.14159265358979323851281 (closest approximation to pi)
343+
// Others:
344+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
345+
0xff, // 3.64519953188247460252841 × 10^−4951 (pseudo-subnormal number)
346+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
347+
0xca, // pseudo-infinity => parsed as nan
348+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
349+
0xca, // infinity
350+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
351+
0xca, // -infinity
352+
0xab, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
353+
0xca, // pseudo-nan
354+
0xab, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
355+
0xca, // nan
356+
0xab, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xfe, 0xca, 0xfe, 0xca, 0xfe,
357+
0xca, // -nan
358+
];
359+
let expected_output = unindent(
360+
"
361+
0000000 3.6451995318824746025e-4951
362+
0000020 3.3621031431120935059e-4932
363+
0000040 3.3621031431120935063e-4932
364+
0000060 1.189731495357231765e+4932
365+
0000100 0.99999999999999999995
366+
0000120 1
367+
0000140 1.0000000000000000001
368+
0000160 2
369+
0000200 -2
370+
0000220 0
371+
0000240 -0
372+
0000260 3.1415926535897932385
373+
0000300 3.6451995318824746025e-4951
374+
0000320 nan
375+
0000340 inf
376+
0000360 -inf
377+
0000400 nan
378+
0000420 nan
379+
0000440 -nan
380+
0000460
381+
",
382+
);
383+
new_ucmd!()
384+
.arg("--endian=little")
385+
.arg("-tfL")
386+
.arg("-w16")
387+
.run_piped_stdin(&input[..])
388+
.success()
389+
.no_stderr()
390+
.stdout_is(expected_output);
391+
}
392+
312393
#[test]
313394
fn test_multibyte() {
314395
let input = "’‐ˆ‘˜語🙂✅🐶𝛑Universität Tübingen \u{1B000}"; // spell-checker:disable-line

0 commit comments

Comments
 (0)