mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
parent
016d83c3fc
commit
3382a2145f
1 changed files with 5 additions and 3 deletions
|
@ -11,7 +11,7 @@ math [-sN | --scale=N] [--] EXPRESSION
|
|||
|
||||
By default, the output is as a float with trailing zeroes trimmed. To get a fixed representation, the `--scale` option can be used, including `--scale=0` for integer output.
|
||||
|
||||
Keep in mind that parameter expansion takes before expressions are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis and the asterisk glob character have to be escaped or quoted.
|
||||
Keep in mind that parameter expansion takes before expressions are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis (`()`) and the asterisk (`*`) glob character have to be escaped or quoted.
|
||||
|
||||
`math` ignores whitespace between arguments and takes its input as multiple arguments (internally joined with a space), so `math 2 +2` and `math "2 + 2"` work the same. `math 2 2` is an error.
|
||||
|
||||
|
@ -35,13 +35,13 @@ For numbers, `.` is always the radix character regardless of locale - `2.5`, not
|
|||
|
||||
- `+` for addition and `-` for subtraction.
|
||||
|
||||
- `*` for multiplication, `/` for division.
|
||||
- `*` for multiplication, `/` for division. (Note that `*` is the glob character and needs to be quoted or escaped)
|
||||
|
||||
- `^` for exponentiation.
|
||||
|
||||
- `%` for modulo.
|
||||
|
||||
- `(` and `)` for grouping.
|
||||
- `(` and `)` for grouping. (These need to be quoted or escaped because `()` denotes a command substitution.)
|
||||
|
||||
They are all used in an infix manner - `5 + 2`, not `+ 5 2`.
|
||||
|
||||
|
@ -97,6 +97,8 @@ All of the trigonometric functions use radians.
|
|||
|
||||
`math "sin(pi)"` outputs `0`.
|
||||
|
||||
`math 5 \* 2` or `math "5 * 2"` or `math 5 "*" 2` all output `10`.
|
||||
|
||||
\subsection math-notes Compatibility notes
|
||||
|
||||
Fish 1.x and 2.x releases relied on the `bc` command for handling `math` expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands.
|
||||
|
|
Loading…
Reference in a new issue