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