This commit is contained in:
olli 2024-06-28 11:24:11 +02:00
parent f5af07290e
commit 855352bdf4

View File

@ -25,8 +25,20 @@ function g_calc {
# send calculation and read result # send calculation and read result
echo "$1" >&${g_fd_bc_in} echo "$1" >&${g_fd_bc_in}
read -u ${g_fd_bc_out} g_calc_result read -u ${g_fd_bc_out} g_calc_result
g_calc_result=${g_calc_result//-./-0.}
g_calc_result=${g_calc_result//./0.} # check if there is a output
if [ -z $g_calc_result ]
then
echo "${FUNCNAME} $@" 1>&2
unset g_calc_result
return 1
fi
# fix bc outpur -> change for example .224 to 0.224 and -.224 to -0.224
[[ $g_calc_result == "."* ]] && g_calc_result="0$g_calc_result"
[[ $g_calc_result == "-."* ]] && g_calc_result="-0.${g_calc_result#-.}"
# check output
if ! g_num_valid_number $g_calc_result if ! g_num_valid_number $g_calc_result
then then
echo "${FUNCNAME} $@" 1>&2 echo "${FUNCNAME} $@" 1>&2