2024年6月6日(木) 15:59 Léa Gris <lea.g...@noiraude.net>:
> 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.

Maybe I miss your point, but literals in arithmetic expressions and
the printf format are unrelated.

Even if Bash is not consistent with ksh/zsh for the printf format, the
floating-point arithmetic of Bash can be made consistent with ksh/zsh.
The floating-point support in arithmetic expressions is not specified
by POSIX/C. Bash is not required anything by POSIX/C about its support
for floating-point arithmetic.

Actually, arithmetic expressions are defined as a subset of C language
in POSIX, so it is natural to follow the floating-point literals in C
if Bash would support floating-point arithmetic. The floating-point
literals in C are unrelated to the result of printf and independent of
the locale where the C compiler runs. E.g. the decimal point is always
`.' in the literals in the C source code. In this sense, even from the
perspective of POSIX/C, there is no reason to adopt the output format
of `printf' for the floating-point numbers in arithmetic expressions
and the results of their evaluation.

--
Koichi

Reply via email to