From 855352bdf4e2ee65dabedef57d413b648674de4d Mon Sep 17 00:00:00 2001 From: olli <> Date: Fri, 28 Jun 2024 11:24:11 +0200 Subject: [PATCH] fixes --- gaboshlib/g_calc.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gaboshlib/g_calc.sh b/gaboshlib/g_calc.sh index c2269f9..04605dd 100644 --- a/gaboshlib/g_calc.sh +++ b/gaboshlib/g_calc.sh @@ -25,8 +25,20 @@ function g_calc { # send calculation and read result echo "$1" >&${g_fd_bc_in} 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 then echo "${FUNCNAME} $@" 1>&2