bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

printf inconsistent results for %.0f


From: Laur Aliste
Subject: printf inconsistent results for %.0f
Date: Mon, 12 Aug 2024 16:30:26 +0200

Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Werror=implicit-function-declaration
-fstack-protector-strong -fstack-clash-protection -Wformat
-Werror=format-security -fcf-protection -Wall
uname output: Linux p14s 6.9.12-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.9.12-1 (2024-07-27) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 21
Release Status: release

Description:
    One of my old script that's been in use for 10+ years is using
built-in bash printf
    for rounding float value to int via `printf`; as of today (Aug 12)
it started
    returning erroneous and inconsistent results.
    Note it doesn't require float input value - trying to format full integers
    reproduces the problem the same.

    Bash version hasn't been updated for ages so assuming it has to be
a dependency issue.

Repeat-By:
    Small sample size of rounding `239.99040` to nearest int:

    ```
    $ printf '%.0f' '239.99040'
    0
    $ printf '%.0f' '239.99040'
    0
    $ printf '%.0f' '239.99040'
    -0
    $ printf '%.0f' '239.99040'
    -27846927597791718682626485772264082260943151763250104531...(trunc)
    $ printf '%.0f' '239.99040'
    -52265319392731843172698376781218204051987087585988880818...(trunc)
    $ printf '%.0f' '239.99040'
    -0
    $ printf '%.0f' '239.99040'
    -51368514663558334697487160651500630134194851172568251199...(trunc)
    ```



reply via email to

[Prev in Thread] Current Thread [Next in Thread]