Skip to content

zsh: support math function calls in arithmetic expressions #1294

@LangLangBart

Description

@LangLangBart
# 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
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions