doc: update THANKS related to env --argv0 option
[coreutils.git] / tests / od / od-float.sh
blobd9aab26b7b144d470926815c5043f349cc9070e5
1 #!/bin/sh
2 # Test od on floating-point values.
4 # Copyright (C) 2010-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ od printf
22 export LC_ALL=C
24 # Test for a bug in coreutils up through 8.7: od was losing
25 # information when asked to parse floating-point values. The numeric
26 # tests are valid only on Intel-like hosts, but that should be good
27 # enough to detect regressions, as they are designed to succeed on
28 # non-Intel-like hosts. Also, test for another bug in coreutils 8.7
29 # on x86: sometimes there was no space between the columns.
31 set x $(echo aaaabaaa | tr ab '\376\377' | od -t fF) ||
32 fail=1
33 case "$*" in
34 *0-*) fail=1;;
35 esac
36 case $3,$4 in
37 -1.694740e+38,-1.694740e+38) fail=1;;
38 esac
40 set x $(echo aaaaaaaabaaaaaaa | tr ab '\376\377' | od -t fD) ||
41 fail=1
42 case "$*" in
43 *0-*) fail=1;;
44 esac
45 case $3,$4 in
46 -5.314010372517808e+303,-5.314010372517808e+303) fail=1;;
47 esac
49 set x $(echo aaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa | tr ab '\376\377' | od -t fL) ||
50 fail=1
51 case "$*" in
52 *0-*) fail=1;;
53 esac
54 case $3,$4 in
55 -1.023442870282055988e+4855,-1.023442870282055988e+4855) fail=1;;
56 esac
58 # Ensure od doesn't crash as it did on glibc <= 2.5:
59 # https://sourceware.org/bugzilla/show_bug.cgi?id=4586
60 set x $(printf 00000000ff000000 | tr 0f '\000\377' | od -t fL) || fail=1
61 # With coreutils <= 8.7 we used to print "nan" for the above invalid value.
62 # However since v8.7-22-ga71c22f we deferred to the system printf routines
63 # through the use of the ftoastr module. So the following check would only
64 # be valid on x86_64 if we again handle the conversion internally or
65 # if this glibc bug is resolved:
66 # https://sourceware.org/bugzilla/show_bug.cgi?id=17661
67 #case "$*" in
68 #*nan*) ;;
69 #*) fail=1;;
70 #esac
72 # Check Half precision IEEE 16 bit float
73 if grep '^#define FLOAT16_SUPPORTED 1' "$CONFIG_HEADER" >/dev/null; then
74 for fmt in '-tfH' '-tf2'; do
75 od_out=$(env printf '\x3C\x00\x3C\x00' | od --end=big -An $fmt | tr -d ' ')
76 test "$od_out" = '11' || fail=1
77 done
78 else
79 echo "od: this system doesn't provide a 'fH' floating point type" > exp_err
80 returns_ 1 od -tfH /dev/null 2>err || fail=1
81 compare exp_err err || fail=1
83 # Check Half precision Brain 16 bit float
84 if grep '^#define BF16_SUPPORTED 1' "$CONFIG_HEADER" >/dev/null; then
85 od_out=$(env printf '\x3F\x80\x3F\x80' | od --end=big -An -tfB | tr -d ' ')
86 test "$od_out" = '11' || fail=1
87 else
88 echo "od: this system doesn't provide a 'fB' floating point type" > exp_err
89 returns_ 1 od -tfB /dev/null 2>err || fail=1
90 compare exp_err err || fail=1
93 Exit $fail