Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zmathfunc: min, max, sum throw error if result equals 0
- X-seq: zsh-workers 48146
- From: "Nikolaus Thiel" <klt@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: zmathfunc: min, max, sum throw error if result equals 0
- Date: Sun, 07 Mar 2021 17:37:09 +0100
- Archived-at: <https://zsh.org/workers/48146>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/m2pn0aj4y2.fsf%40zaclys.net>
- Dmarc-filter: OpenDMARC Filter v1.3.2 mail.zaclys.net 127Gb9Hf026598
- List-id: <zsh-workers.zsh.org>
There seems to be a bug in zmathfunc:
When the result of min, max or sum equals 0, the functions throw an error. If
they are used within a script with the option "set -e" then the script aborts,
cf. test script below.
I have confirmed this behaviour on two systems:
(1) Apple MacBook Air, Ubuntu 20.04.2 LTS
Linux Luftbuch 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
zsh 5.8 (x86_64-ubuntu-linux-gnu)
(2) Apple iMac, macOS 11.2.2
Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64
zsh 5.8 (x86_64-apple-darwin20.0)
-------- Test Script --------
#!/usr/bin/env zsh
set -e
OS=$(uname)
if [[ ${OS} == "Darwin" ]]; then
### Mac OS X
source /usr/share/zsh/5.8/functions/zmathfunc
else
### Ubuntu 20.04
source /usr/share/zsh/functions/Math/zmathfunc
fi
echo "OS = ${OS}"
zsh --version
echo "works fine"
x=$(( min(2,-1,3) ))
echo "min(2,1,3) = $((x))"
x=$(( max(2,-1,3) ))
echo "max(2,-1,3) = $((x))"
x=$(( sum(2,-1,3) ))
echo "sum(2,-1,3) = $((x))"
echo "min, max, sum throw an error if result=0"
echo " => set -e causes script to abort"
x=$(( sum(-2,2) ))
echo "sum(-2,2) = $((x))"
x=$(( min(2,0,3) ))
echo "min(2,0,3) = $((x))"
x=$(( max(-2,0,-3) ))
echo "max(-2,0,-3) = $((x))"
-------- Output on Mac OS X --------
OS = Darwin
zsh 5.8 (x86_64-apple-darwin20.0)
works fine
min(2,1,3) = -1
max(2,-1,3) = 3
sum(2,-1,3) = 4
min, max, sum throw an error if result=0
=> set -e causes script to abort
-------- Output on Ubuntu --------
OS = Linux
zsh 5.8 (x86_64-ubuntu-linux-gnu)
works fine
min(2,1,3) = -1
max(2,-1,3) = 3
sum(2,-1,3) = 4
min, max, sum throw an error if result=0
=> set -e causes script to abort
Messages sorted by:
Reverse Date,
Date,
Thread,
Author