diff options
| author | dana <dana@dana.is> | 2026-04-13 11:04:58 -0500 |
|---|---|---|
| committer | dana <dana@dana.is> | 2026-04-13 11:07:56 -0500 |
| commit | bfb982d6824a41ebff1fc5934ebee7f01df1e682 (patch) | |
| tree | 4cf710d17dcd411e88f1f5261ed96ec15202c394 /Doc/Zsh | |
| parent | 54313: convfloat: use consistent capitalisation for NaN, Inf, and -Inf (diff) | |
| download | zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.tar zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.tar.gz zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.tar.bz2 zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.tar.lz zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.tar.xz zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.tar.zst zsh-bfb982d6824a41ebff1fc5934ebee7f01df1e682.zip | |
54318: mathfunc: add isnan() and isinf(). also document NaN + Inf
Diffstat (limited to 'Doc/Zsh')
| -rw-r--r-- | Doc/Zsh/arith.yo | 27 | ||||
| -rw-r--r-- | Doc/Zsh/mod_mathfunc.yo | 4 |
2 files changed, 29 insertions, 2 deletions
diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo index f8807eb4a..17eb3cc36 100644 --- a/Doc/Zsh/arith.yo +++ b/Doc/Zsh/arith.yo @@ -122,6 +122,33 @@ taken for a parameter name. All numeric parts (before and after the decimal point and in the exponent) may contain underscores after the leading digit for visual guidance; these are ignored in computation. +The special floating point values NaN (not a number) and infinity are +fully supported in floating point arithmetic. They may be produced by +certain operations, such as division by zero, or referenced explicitly in +arithmetic constructs and float assignments using the case-insensitive +constants tt(NaN) and tt(Inf). Expansion syntax must be used to +reference a parameter with one of these names in these contexts: + +example(% nan=123 INF=456 +% print $LPAR()LPAR() nan RPAR()RPAR() $LPAR()LPAR() INF RPAR()RPAR() +NaN Inf +% print $LPAR()LPAR() $nan RPAR()RPAR() $LPAR()LPAR() $INF RPAR()RPAR() +123 456 +% typeset -F f=nan && typeset -p f +typeset -F f=NaN +% typeset -F f=$nan && typeset -p f +typeset -F f=123.0000000000) + +To check whether a value is NaN, either use the tt(isnan) function +provided by the tt(zsh/mathfunc) module +or compare it to the string tt(NaN): + +example(% zmodload zsh/mathfunc +% (( isnan(0.0 / 0) )) && print is nan +is nan +% typeset -F f=nan && [[ $f == NaN ]] && print is nan +is nan) + cindex(arithmetic operators) cindex(operators, arithmetic) An arithmetic expression uses nearly the same syntax and diff --git a/Doc/Zsh/mod_mathfunc.yo b/Doc/Zsh/mod_mathfunc.yo index 61aa3decf..b7223e2cf 100644 --- a/Doc/Zsh/mod_mathfunc.yo +++ b/Doc/Zsh/mod_mathfunc.yo @@ -27,8 +27,8 @@ tt(floor), tt(gamma), tt(j0), tt(j1), tt(lgamma), tt(log), tt(log10), tt(log1p), tt(log2), tt(logb), tt(sin), tt(sinh), tt(sqrt), tt(tan), tt(tanh), tt(y0), tt(y1). The tt(atan) function can optionally take a second argument, in which case it behaves like the C function tt(atan2). -The tt(ilogb) function takes a single floating point argument, but -returns an integer. +The tt(ilogb), tt(isinf), and tt(isnan) functions take a single floating +point argument, but return an integer. The function tt(signgam) takes no arguments, and returns an integer, which is the C variable of the same name, as described in manref(gamma)(3). Note |
