mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 04:40:59 +01:00
48606 + 48607 + unposted test: zmathfunc: Force arguments to be numbers and catch errors.
This commit is contained in:
parent
e7711e37e4
commit
b0bd14035d
3 changed files with 24 additions and 4 deletions
|
|
@ -6,7 +6,12 @@ zsh_math_func_min() {
|
|||
shift
|
||||
local arg
|
||||
for arg ; do
|
||||
(( $arg < result )) && result=$arg
|
||||
(( arg < result ))
|
||||
case $? in
|
||||
(0) (( result = arg ));;
|
||||
(1) ;;
|
||||
(*) return $?;;
|
||||
esac
|
||||
done
|
||||
(( result ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
|
|
@ -19,7 +24,12 @@ zsh_math_func_max() {
|
|||
shift
|
||||
local arg
|
||||
for arg ; do
|
||||
(( $arg > result )) && result=$arg
|
||||
(( arg > result ))
|
||||
case $? in
|
||||
(0) (( result = arg ));;
|
||||
(1) ;;
|
||||
(*) return $?;;
|
||||
esac
|
||||
done
|
||||
(( result ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
|
|
@ -31,7 +41,7 @@ zsh_math_func_sum() {
|
|||
local sum
|
||||
local arg
|
||||
for arg ; do
|
||||
(( sum += $arg ))
|
||||
(( sum += arg ))
|
||||
done
|
||||
(( sum ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue