Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding shell functions to obtain minimum/maximum of two numbers
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Apr 26, 2016
1 parent f8fdf60 commit 118b0ca
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/test.sh
Expand Up @@ -50,3 +50,31 @@ EOF

return $error
}

# returns minimum of two numbers
min() {
local a=$(echo "$1" | sed -e 's/[eE]+*/*10^/')
local b=$(echo "$2" | sed -e 's/[eE]+*/*10^/')
cat <<EOF | bc -l
define min(i,j) {
if (i < j) return i
return j
}
min($a,$b)
EOF
}

# returns maximum of two numbers
max() {
local a=$(echo "$1" | sed -e 's/[eE]+*/*10^/')
local b=$(echo "$2" | sed -e 's/[eE]+*/*10^/')
cat <<EOF | bc -l
define max(i,j) {
if (i > j) return i
return j
}
max($a,$b)
EOF
}

0 comments on commit 118b0ca

Please sign in to comment.