Le Wed, Jul 09, 2025 at 09:40:16AM -0400, Chet Ramey a écrit :
> On 7/8/25 8:32 PM, Isabella Bosia wrote:
> > bash: fltexpr: 1e10000: number out of range (error token is "1e10000")
>
> What do you propose? Catch HUGE_VAL/ERANGE and convert to Inf?
Far before HUGE numbers, speaking about TERA, there seem to be some issue:
for i in 1{,0,00,000,0000,00000,000000}.0;do
printf '99999999999999 / %s : ' $i
fltexpr -p " 99999999999999.9 / i"
done
99999999999999 / 1.0 : 99999999999899.90625
99999999999999 / 10.0 : 9999999999989.990234375
99999999999999 / 100.0 : 999999999998.9990234375
99999999999999 / 1000.0 : 99999999999.999908
99999999999999 / 10000.0 : 9999999999.99999
99999999999999 / 100000.0 : 999999999
99999999999999 / 1000000.0 : 99999999
Note: I was trying to build an ``humanizeVar'' function:
humanizeVar() {
local -i pos fact=${humanizeVarFactor:-1024}
local ar=(b K M G T P E Z Y R Q) res i
case $1 in
-K ) ar=("${ar[@]:1}"); shift ;;
-M ) ar=("${ar[@]:2}"); shift ;;
-G ) ar=("${ar[@]:3}"); shift ;;
-T ) ar=("${ar[@]:4}"); shift ;;
esac
for i; do
if [[ ${!i} == *[!0-9.]* ]] || ! (( $i )); then
printf -v "$i" '0.00%s' ${ar[0]}
continue
fi
fltexpr "pos= floor( log($i) / log(fact) ), res= $i / fact ** pos"
printf -v "$i" '%.2f%s' $res ${ar[pos]:-x1K^$pos}
done
}
Then
var=99999999999999;humanizeVar var;echo $var
90.95T
looks good, but
var=99999999999999;humanizeVarFactor=1000 humanizeVar var;echo $var
99.00T
should sow '100.00T' instead!
--
Félix Hauri - <[email protected]> - http://www.f-hauri.ch