[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: REQUEST - bash floating point math support
From: |
Léa Gris |
Subject: |
Re: REQUEST - bash floating point math support |
Date: |
Mon, 17 Jun 2024 09:47:48 +0200 |
User-agent: |
Mozilla Thunderbird |
Le 17/06/2024 à 09:17, Koichi Murase écrivait :
declare -i numvar=${localeFormatted/[!0-9]/.}
This would break with negative numbers.
I know no other radix separator than comma or dot. If there are other
radix to replace, it can be listed in a character class.
Lets say there are locales that uses , ; or :
declare -i numvar=${localeFormatted/[,;:]/.}
In my opinion, the locale-formatted strings should only appear in the
strings presented to users, such as in the output of `printf'. It is
easier and maintainable to normalize all the internal representations
to be the C floating-point literals.
I have been in IT in France since 3 decades. And I have never ever found
any piece of code that use locale-formatted literals, not even during my
CS education.
Sometimes one have to deal with data sources with numbers formatted in
funny ways, even grouping with illegal characters. Then it is a know
fact that one must deal with sourced data with zealous sanitizing.
Now on the bash shell context. The usual pitfall with floating-point
number parsing comes when some script author tries to parse output of a
command that is not meant to be parsed, that is locale formatted and
don't bother to set LC_NUMERIC=C before running this command
A common pitfall is trying to parse the output of the time builtin command.
It already breaks on locale ignorant scripts. This won't change.
--
Léa Gris
- Re: REQUEST - bash floating point math support, (continued)
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/14
- Re: REQUEST - bash floating point math support, Saint Michael, 2024/06/14
- Re: REQUEST - bash floating point math support, Koichi Murase, 2024/06/14
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/15
- Re: REQUEST - bash floating point math support, Koichi Murase, 2024/06/15
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/15
- Re: REQUEST - bash floating point math support, alex xmb sw ratchev, 2024/06/15
- Re: REQUEST - bash floating point math support, Zachary Santer, 2024/06/16
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/17
- Re: REQUEST - bash floating point math support, Koichi Murase, 2024/06/17
- Re: REQUEST - bash floating point math support,
Léa Gris <=
- Re: REQUEST - bash floating point math support, Zachary Santer, 2024/06/17
- Re: REQUEST - bash floating point math support, Chet Ramey, 2024/06/21
- Re: REQUEST - bash floating point math support, alex xmb sw ratchev, 2024/06/21
- Re: REQUEST - bash floating point math support, Chet Ramey, 2024/06/21
- Re: REQUEST - bash floating point math support, Saint Michael, 2024/06/21
- Re: REQUEST - bash floating point math support, alex xmb sw ratchev, 2024/06/21
- Re: REQUEST - bash floating point math support, Chet Ramey, 2024/06/21
- Re: REQUEST - bash floating point math support, Chet Ramey, 2024/06/12
- Re: REQUEST - bash floating point math support, Robert Elz, 2024/06/05
- Re: REQUEST - bash floating point math support, Greg Wooledge, 2024/06/05