On 27/09/2026 20:54, Iván Ezequiel Rodriguez wrote:
The printf-posix module already provides %a; add a regression
test matching the example from --help.

* tests/printf/printf-a.sh: New test.
* tests/local.mk (all_tests): Add it.

Signed-off-by: Iván Ezequiel Rodriguez <[email protected]>
---
  tests/local.mk           |  1 +
  tests/printf/printf-a.sh | 30 ++++++++++++++++++++++++++++++
  2 files changed, 31 insertions(+)
  create mode 100755 tests/printf/printf-a.sh

diff --git a/tests/local.mk b/tests/local.mk
index ca2a0b8..bdfe793 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -415,6 +415,7 @@ all_tests =                                 \
    tests/paste/multi-byte.sh                   \
    tests/printf/printf.sh                      \
    tests/printf/printf-cov.pl                  \
+  tests/printf/printf-a.sh                     \
    tests/printf/printf-hex.sh                  \
    tests/printf/printf-indexed.sh              \
    tests/printf/printf-mb.sh                   \
diff --git a/tests/printf/printf-a.sh b/tests/printf/printf-a.sh
new file mode 100755
index 0000000..5040e52
--- /dev/null
+++ b/tests/printf/printf-a.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Ensure printf(1) supports the %a hex-float conversion.
+
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ printf
+
+# Example from the --help table (value 2^-10).
+env printf '%a\n' 0.0009765625 > out || fail=1
+# Accept either 0x8p-13 or 0x1p-10 (both represent the same value).
+case $(cat out) in
+  0x8p-13|0x1p-10|0X8P-13|0X1P-10) ;;
+  *) cat out; fail=1 ;;
+esac
+
+Exit $fail

Well theoretically there could be many other valid hex values.
It seems better to me to test we can round trip. Something like:

  fv=0.0009765625
  test $(env printf '%.10f' $(env printf %a $fv)) = $fv || fail=1
  env printf %a $fv | grep '^0[xX]' || fail=1

Also this is too small for a separate test file,
so would be better in printf.sh

Also it's better to send patches to [email protected]
to avoid tracking bugs for each one.

thanks,
Padraig






Reply via email to