2024年6月6日(木) 18:09 Léa Gris <lea.g...@noiraude.net>: > Le 06/06/2024 à 10:29, Koichi Murase écrivait : > > 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. > > They are in Bash. Bash use the locale format for floating-point number > arguments.
The arguments of `printf' are not in an arithmetic context. This is the case even for the currently supported integers. If it were an arithmetic context, « printf %d 1+1 » should have printed `2', but the actual result is an error because the arguments of the `printf' builtin are unrelated to the arithmetic expression. Though, I see your point. It is inconvenient that we cannot pass the results of arithmetic evaluations to the `printf' builtin. This appears to be an issue of the printf builtin. I think the `printf' builtin should be extended to interpret both forms of the numbers, the locale-dependent formatted number and the floating-point literals. A problem is POSIX. I checked POSIX which states that the arguments of the `printf' utility for %f, etc. shall be interpreted by strtod(), and that strtod() shall use the locale-defined radix character and shall fail if it is in an unexpected format. By combining these statements, POSIX does not allow extension of the number format in the arguments of the printf builtin, which seems an unreasonable restriction. -- Koichi