1
0
Fork 0
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:
Daniel Shahaf 2021-04-21 21:59:45 +00:00
parent e7711e37e4
commit b0bd14035d
3 changed files with 24 additions and 4 deletions

View file

@ -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