From: "Nikolaus Thiel" <klt@fsfe.org>
To: zsh-workers@zsh.org
Subject: zmathfunc: min, max, sum throw error if result equals 0
Date: Sun, 07 Mar 2021 17:37:09 +0100 [thread overview]
Message-ID: <m2pn0aj4y2.fsf@zaclys.net> (raw)
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
next reply other threads:[~2021-03-07 16:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-07 16:37 Nikolaus Thiel [this message]
2021-03-07 17:17 ` Daniel Shahaf
2021-03-07 21:39 ` Bart Schaefer
2021-03-07 21:56 ` Daniel Shahaf
2021-03-08 2:25 ` Bart Schaefer
2021-04-16 18:26 ` Daniel Shahaf
2021-04-16 18:47 ` Bart Schaefer
2021-04-16 19:50 ` Daniel Shahaf
2021-04-16 20:05 ` Bart Schaefer
2021-04-16 20:08 ` Daniel Shahaf
2021-04-16 18:21 ` Daniel Shahaf
2021-05-16 14:54 ` Lawrence Velázquez
2021-05-18 2:02 ` Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2pn0aj4y2.fsf@zaclys.net \
--to=klt@fsfe.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).