On 6/5/24 2:59 AM, Léa Gris wrote:
Le 05/06/2024 à 17:09, Koichi Murase écrivait :
2024年6月5日(水) 21:41 Zachary Santer <zsan...@gmail.com>:
Bash could potentially detect floating point literals within
arithmetic expansions and adjust the operations to use floating point
math in that case. [...]

ksh and zsh are already behaving in that way, and if Bash would
support the floating-point arithmetic, Bash should follow their
behavior.

Bash isn't even consistent with the floating point data/input format when using printf '%f\n' "$float_string" as it depends on LC_NUMERIC locale.

LC_MESSAGES=C LC_NUMERIC=fr_FR.UTF8 printf '%f\n' 3.1415
bash: printf: 3.1415: invalid number
3,000000


Chet explained it is because Bash is following the POSIX norm and C printf rules.

This is true. The printf(3) engine, which bash uses to display floating
point numbers, uses the radix character from the LC_NUMERIC locale
category.

The arguments to printf(1) have to be converted to floating point format
to pass to printf(3). strtod(3), which bash uses to perform this
conversion, uses the radix character from LC_NUMERIC as well.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to