On Tue, Jun 4, 2024 at 4:01 PM Saint Michael <vene...@gmail.com> wrote: > > > > > It's time to add floating point variables and math to bash. > > It just makes so much easier to solve business problems without external > calls to bc or Python. > Please let's overcome the "shell complex". Let's treat bash a real language.
You want to expound on use cases? I've seen one, for myself: writing a script to bind keyboard shortcuts to, so I could change the level of screen magnification in GNOME by increments of less than 100%. The magnification factor is handled as a fractional number - 1.5, 1.75, etc. So, to change the magnification factor by increments of 0.25 or 0.5, I had to print an expression into bc in a command substitution. The math that people want to do in bash is going to be integer the vast majority of the time, though, and scripts are of course written to expect integer math. Bash could potentially detect floating point literals within arithmetic expansions and adjust the operations to use floating point math in that case. I believe C treats a literal 10 as an integer and a literal 10.0 as a floating point number, for instance, so this wouldn't really be going against the grain. For completeness, a floating point variable attribute could potentially be added. 'declare -i var' will cause var to be treated as an integer, though var can be referenced within an arithmetic expansion without this attribute. declare -f and -r (real, anybody?) are already taken for other things, so I'm not sure what the natural choice of option would be. Zack