new
This commit is contained in:
parent
53c2651fa8
commit
778682b382
@ -1,9 +1,11 @@
|
|||||||
function g_calc {
|
function g_calc {
|
||||||
|
|
||||||
# Use bc in backround for multiple bc's running much faster
|
# Use bc in backround for multiple bc's running much faster
|
||||||
|
echo "start g_calc"
|
||||||
if [ -z "${g_bc_running}" ]
|
if [ -z "${g_bc_running}" ]
|
||||||
then
|
then
|
||||||
g_rnd=$$
|
g_rnd=$$
|
||||||
|
echo "g_calc new fds"
|
||||||
mkdir -p ${g_tmp}/${g_rnd}
|
mkdir -p ${g_tmp}/${g_rnd}
|
||||||
[ -p ${g_tmp}/${g_rnd}/bc-in ] || mkfifo ${g_tmp}/${g_rnd}/bc-in
|
[ -p ${g_tmp}/${g_rnd}/bc-in ] || mkfifo ${g_tmp}/${g_rnd}/bc-in
|
||||||
[ -p ${g_tmp}/${g_rnd}/bc-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-out
|
[ -p ${g_tmp}/${g_rnd}/bc-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-out
|
||||||
@ -50,5 +52,5 @@ function g_calc {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# echo result
|
# echo result
|
||||||
echo ${g_sed_out}
|
g_calc_result="${g_sed_out}"
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ function g_num_is_approx {
|
|||||||
|
|
||||||
g_num_valid_number "${f_num}" "${f_base}" "${f_percentage_up}" "${f_percentage_down}" || return 1
|
g_num_valid_number "${f_num}" "${f_base}" "${f_percentage_up}" "${f_percentage_down}" || return 1
|
||||||
|
|
||||||
local f_from=$(g_calc "${f_base} - (${f_base} / 100 * ${f_percentage_down})")
|
g_calc "${f_base} - (${f_base} / 100 * ${f_percentage_down})"
|
||||||
local f_to=$(g_calc "${f_base} + (${f_base} / 100 * ${f_percentage_up})")
|
local f_from=${g_calc_result}
|
||||||
|
g_calc "${f_base} + (${f_base} / 100 * ${f_percentage_up})"
|
||||||
|
local f_to=${g_calc_result}
|
||||||
|
|
||||||
g_num_is_between ${f_num} ${f_from} ${f_to}
|
g_num_is_between ${f_num} ${f_from} ${f_to}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@ function g_num_is_between {
|
|||||||
g_num_valid_number "$f_num" "$f_between1" "$f_between2" || return 1
|
g_num_valid_number "$f_num" "$f_between1" "$f_between2" || return 1
|
||||||
|
|
||||||
# Check which is the low (from) and the high (to) number
|
# Check which is the low (from) and the high (to) number
|
||||||
if [ $(g_calc "${f_between1} < ${f_between2}") -ne 0 ]
|
g_calc "${f_between1} < ${f_between2}"
|
||||||
|
if [ ${g_calc_result} -ne 0 ]
|
||||||
then
|
then
|
||||||
local f_from=${f_between1}
|
local f_from=${f_between1}
|
||||||
local f_to=${f_between2}
|
local f_to=${f_between2}
|
||||||
@ -38,7 +39,11 @@ function g_num_is_between {
|
|||||||
local f_to=${f_between1}
|
local f_to=${f_between1}
|
||||||
fi
|
fi
|
||||||
# Check if given number is in or out range
|
# Check if given number is in or out range
|
||||||
if [ $(g_calc "${f_num} < ${f_from}") -ne 0 ] || [ $(g_calc "${f_num} > ${f_to}") -ne 0 ]
|
g_calc "${f_num} < ${f_from}"
|
||||||
|
local g_calc_result_from="${g_calc_result}"
|
||||||
|
g_calc "${f_num} > ${f_to}"
|
||||||
|
local g_calc_result_to="${g_calc_result}"
|
||||||
|
if [ ${g_calc_result_from} -ne 0 ] || [ ${g_calc_result_to} -ne 0 ]
|
||||||
then
|
then
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
|
@ -18,7 +18,8 @@ function g_num_is_higher_equal {
|
|||||||
# Check for valid number
|
# Check for valid number
|
||||||
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
||||||
|
|
||||||
if [ $(g_calc "${f_num} >= ${f_checkhigher}") -ne 0 ]
|
g_calc "${f_num} >= ${f_checkhigher}"
|
||||||
|
if [ ${g_calc_result} -ne 0 ]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -46,7 +47,8 @@ function g_num_is_higher {
|
|||||||
# Check for valid number
|
# Check for valid number
|
||||||
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
||||||
|
|
||||||
if [ $(g_calc "${f_num} > ${f_checkhigher}") -ne 0 ]
|
g_calc "${f_num} > ${f_checkhigher}"
|
||||||
|
if [ ${g_calc_result} -ne 0 ]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -18,7 +18,8 @@ function g_num_is_lower_equal {
|
|||||||
# Check for valid number
|
# Check for valid number
|
||||||
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
||||||
|
|
||||||
if [ $(g_calc "${f_num} <= ${f_checkhigher}") -ne 0 ]
|
g_calc "${f_num} <= ${f_checkhigher}"
|
||||||
|
if [ ${g_calc_result} -ne 0 ]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -47,7 +48,7 @@ function g_num_is_lower {
|
|||||||
# Check for valid number
|
# Check for valid number
|
||||||
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
g_num_valid_number "$f_num" "$f_checkhigher" || return 1
|
||||||
|
|
||||||
if [ $(g_calc "${f_num} < ${f_checkhigher}") -ne 0 ]
|
if [ ${g_calc_result} -ne 0 ]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -4,7 +4,10 @@ function g_percentage-diff {
|
|||||||
local g_from=$1
|
local g_from=$1
|
||||||
local g_to=$2
|
local g_to=$2
|
||||||
g_num_valid_number "$g_from" "$g_to" || return 1
|
g_num_valid_number "$g_from" "$g_to" || return 1
|
||||||
[ $(g_calc "${g_from} == 0") -eq 1 ] && return 1
|
g_calc "${g_from} == 0"
|
||||||
[ $(g_calc "${g_to} == 0") -eq 1 ] && return 1
|
[ ${g_calc_result} -eq 1 ] && return 1
|
||||||
printf -- "%.2f" $(g_calc "100/${g_from}*(${g_to}-${g_from})")
|
g_calc "${g_to} == 0"
|
||||||
|
[ ${g_calc_result} -eq 1 ] && return 1
|
||||||
|
g_calc "100/${g_from}*(${g_to}-${g_from})"
|
||||||
|
g_percentage_diff_result=$(printf -- "%.2f" "${g_calc_result}")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user