zsh-workers
 help / color / mirror / code / Atom feed
* zmathfunc: min, max, sum throw error if result equals 0
@ 2021-03-07 16:37 Nikolaus Thiel
  2021-03-07 17:17 ` Daniel Shahaf
  0 siblings, 1 reply; 13+ messages in thread
From: Nikolaus Thiel @ 2021-03-07 16:37 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-05-18  2:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-07 16:37 zmathfunc: min, max, sum throw error if result equals 0 Nikolaus Thiel
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

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).