make local variables local
.. to not interfere with variables in the scripts that source these utils.
This commit is contained in:
17
math.sh
17
math.sh
@@ -8,6 +8,11 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
# https://unix.stackexchange.com/questions/89712/how-to-convert-floating-point-number-to-integer
|
||||
# xargs: https://stackoverflow.com/questions/19148370/piping-seq-to-printf-for-number-formatting
|
||||
divideint () {
|
||||
if [ -z $3 ]; then
|
||||
local scale=2
|
||||
else
|
||||
local scale=$3
|
||||
fi
|
||||
bc <<< "scale=$scale; $1/$2" | xargs printf "%.0f\n"
|
||||
}
|
||||
|
||||
@@ -17,25 +22,25 @@ multiint () {
|
||||
|
||||
divide () {
|
||||
if [ -z $3 ]; then
|
||||
scale=2
|
||||
local scale=2
|
||||
else
|
||||
scale=$3
|
||||
local scale=$3
|
||||
fi
|
||||
bc <<< "scale=$scale; $1/$2"
|
||||
}
|
||||
|
||||
multiply () {
|
||||
if [ -z $3 ]; then
|
||||
scale=2
|
||||
local scale=2
|
||||
else
|
||||
scale=$3
|
||||
local scale=$3
|
||||
fi
|
||||
bc <<< "scale=$scale; $1*$2"
|
||||
}
|
||||
|
||||
avgoftwo () {
|
||||
sum=$(bc <<< "$1+$2")
|
||||
divideint $sum 2
|
||||
local sum=$(bc <<< "$1+$2")
|
||||
divide $sum 2
|
||||
}
|
||||
|
||||
max () {
|
||||
|
||||
Reference in New Issue
Block a user