summaryrefslogtreecommitdiff
path: root/Functions/Math/zmathfunc
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Math/zmathfunc')
-rw-r--r--Functions/Math/zmathfunc26
1 files changed, 21 insertions, 5 deletions
diff --git a/Functions/Math/zmathfunc b/Functions/Math/zmathfunc
index 4ff40700d..12d2c2f3d 100644
--- a/Functions/Math/zmathfunc
+++ b/Functions/Math/zmathfunc
@@ -1,34 +1,50 @@
#autoload
zsh_math_func_min() {
+ emulate -L zsh
local result=$1
shift
local arg
for arg ; do
- (( $arg < result )) && result=$arg
+ (( arg < result ))
+ case $? in
+ (0) (( result = arg ));;
+ (1) ;;
+ (*) return $?;;
+ esac
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
+ (( arg > result ))
+ case $? in
+ (0) (( result = arg ));;
+ (1) ;;
+ (*) return $?;;
+ esac
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 ))
+ (( sum += arg ))
done
(( sum ))
+ true # Careful here: `return 0` evaluates an arithmetic expression
}
functions -M sum 0 -1 zsh_math_func_sum