mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-24 17:00:32 +02:00
48147/0002: zmathfunc: Fix bug where the exit code would be non-zero if the expression evaluted to zero.
This commit is contained in:
parent
6a2a8acf09
commit
f87b73e677
3 changed files with 13 additions and 3 deletions
|
|
@ -1,34 +1,40 @@
|
|||
#autoload
|
||||
|
||||
zsh_math_func_min() {
|
||||
emulate -L zsh
|
||||
local result=$1
|
||||
shift
|
||||
local arg
|
||||
for arg ; do
|
||||
(( $arg < result )) && result=$arg
|
||||
done
|
||||
(( result )) # return
|
||||
(( result ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
}
|
||||
functions -M min 1 -1 zsh_math_func_min # at least one argument
|
||||
|
||||
zsh_math_func_max() {
|
||||
emulate -L zsh
|
||||
local result=$1
|
||||
shift
|
||||
local arg
|
||||
for arg ; do
|
||||
(( $arg > result )) && result=$arg
|
||||
done
|
||||
(( result )) # return
|
||||
(( result ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
}
|
||||
functions -M max 1 -1 zsh_math_func_max # at least one argument
|
||||
|
||||
zsh_math_func_sum() {
|
||||
emulate -L zsh
|
||||
local sum
|
||||
local arg
|
||||
for arg ; do
|
||||
(( sum += $arg ))
|
||||
done
|
||||
(( sum ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
}
|
||||
functions -M sum 0 -1 zsh_math_func_sum
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue