Sample Header Ad - 728x90

Bash printf float formatting became nonsensical and random

7 votes
3 answers
367 views
Bash printf floating number formatting (with %f or %g) is suddenly completely wrong, and changing all the time. An example output:
$ export LC_ALL=C
$ printf '%g\n' 1
1.20739e+3531
$ printf '%g\n' 1
4.50784e-4778
$ printf '%g\n' 1
1.20739e+3531
$ printf '%g\n' 1
-2.71289e-809
$ printf '%g\n' 1
1.3505e+3136
$ printf '%g\n' 1
7.19546e+2880
$ printf '%f\n' 1
0.000000
$ printf '%f\n' 1
-19222373783767455764509969957314767706032565305205751517976389011586356910287283735873496366975075385910809025031233228909443235485943598697862160225065543796566324326303010027986380740507313362109478389280032720809755605977575591712977484833714421549464179548312816619669691695969675768618124142786377660052446990574866227828104911221712770547544994592495621702453486060768120985842267603349960735550433657827156688542311891238932963870595675569407105652838611000368894193915118759451716250477855842495787217908770520219596001805968923516834815448319714521179606192054239712352794281273655344703644255690153172028191401140768961585354430400117766273628103129509500449952562778071128862373050266582261154261590345666202936676378315868263637718127652344391988248019089245237502067305800855582602326233046151999935749805709388443164385685796904118233897433899895164143403147924128628840995216653448904704.000000
$ printf '%f\n' 1
-1535939692251970798780814048195400843655654544941633379309930935432267368465724365567117453392273362651582982424721184431169329486749020702578930669204206705946793193732917405530938783202632819503328225917797530425669645856818642162664722510713747202433401571296943178862058175872487260754269792220244257605097737000140353828109440097622967061126831273879953063844519410176251996107980841451192710472925184.000000
$ printf '%f\n' 1
-559936185544451048996856397218869061556420299014564433770484452018186365447891968084773838558135844864.000000
It is bash builtin that is being used, as I can see when typing command -v printf. alias printf says "not found". I have the binaries at /bin/printf and /usr/bin/printf that behave normally. Awk and Python equivalent commands behave normally. Interestingly, when using sh, it's fine too. I am on Debian testing, and I tried to apt upgrade and reboot but the bug persists. Bash version is GNU bash, version 5.2.32(1)-release (x86_64-pc-linux-gnu). I tried apt reinstall bash without success. Yesterday for another reason I did a apt-get dist-upgrade. What have I done?! It's wild. [EDIT: additional debugging below] - Run a Memtest86+ for 12 passes, detected no error. - recompiled [Bash 5.2.32 from GNU](https://www.gnu.org/software/bash/) , it has the problem. - tried as another user. - This bug has been reported here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1078556 . I guess I am going to continue this topic with the Debian bug report system. Here is the content of /etc/apt/sources.list:
deb https://deb.debian.org/debian/  testing main contrib non-free non-free-firmware
deb-src https://deb.debian.org/debian/  testing main contrib non-free non-free-firmware contrib

deb http://security.debian.org/debian-security  testing-security main contrib non-free non-free-firmware contrib
deb-src http://security.debian.org/debian-security  testing-security main contrib non-free non-free-firmware contrib
and I also have /etc/apt/preferences.d/security as suggested in [Best practices for Testing users](https://wiki.debian.org/DebianTesting#Best_practices_for_Testing_users) :
Package: src:chromium src:firefox src:firefox-esr src:linux src:linux-signed-amd64
Explanation: these packages are always security updates updated in unstable first
Pin: release a=/^(unstable|unstable-debug|buildd-unstable|buildd-unstable-debug)$/
Pin-Priority: 980
Asked by PlasmaBinturong (751 rep)
Sep 17, 2024, 01:20 PM
Last activity: Feb 1, 2025, 02:20 PM