about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-21 21:59:45 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-21 22:05:00 +0000
commitb0bd14035d1e2747ff98c46ca8715aab4f9533ea (patch)
treeb11c520c1cbbd2693a3a3838b39e8ccd3ba38e51 /Functions
parente7711e37e4a85338a4717ca5791940bc64878afb (diff)
downloadzsh-b0bd14035d1e2747ff98c46ca8715aab4f9533ea.tar.gz
zsh-b0bd14035d1e2747ff98c46ca8715aab4f9533ea.tar.xz
zsh-b0bd14035d1e2747ff98c46ca8715aab4f9533ea.zip
48606 + 48607 + unposted test: zmathfunc: Force arguments to be numbers and catch errors.
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Math/zmathfunc16
1 files changed, 13 insertions, 3 deletions
diff --git a/Functions/Math/zmathfunc b/Functions/Math/zmathfunc
index 8e4b78549..12d2c2f3d 100644
--- a/Functions/Math/zmathfunc
+++ b/Functions/Math/zmathfunc
@@ -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