#1294·sh

zsh: support math function calls in arithmetic expressions

Author: LangLangBartCreated Mar 17, 2026Updated Mar 17, 2026
Labelszsh
bash
# NOTE: requires the `zsh/mathfunc` module to be active
zmodload zsh/mathfunc

echo $(( abs(-5) ))
# 5

echo $(( pi = 4.0 * atan(1.0) ))
# 3.1415926535897931

echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))
# -1.1102230246251565e-16
bash
shfmt --language-dialect zsh <<<'echo $(( abs(-5) ))'
# <standard input>:1:13: not a valid arithmetic operator: `(`

shfmt --language-dialect zsh <<<'echo $(( pi = 4.0 * atan(1.0) ))'
# <standard input>:1:25: not a valid arithmetic operator: `(`

shfmt --language-dialect zsh <<<'echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))'
# <standard input>:1:13: not a valid arithmetic operator: `(`

zsh docs

https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fmathfunc-Module