fix math regression

The previous change to use `argparse` for parity with every other
builtin and function introduced a regression. Invocations that start
with a negative number can fail because the negative value looks like an
invalid flag.
This commit is contained in:
Kurtis Rader
2017-07-14 16:03:31 -07:00
parent ff4d275f22
commit 98449fec51
4 changed files with 30 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
\subsection math-synopsis Synopsis
\fish{synopsis}
math [-sN] EXPRESSION
math [-sN | --scale=N] [--] EXPRESSION
\endfish
\subsection math-description Description
@@ -13,7 +13,7 @@ For a description of the syntax supported by math, see the manual for the bc pro
The following options are available:
- `-sN` Sets the scale of the result. `N` must be an integer and defaults to zero. This simply sets bc's `scale` variable to the provided value. Note that you cannot put a space between `-s` and `N`.
- `-sN` or `--scale=N` sets the scale of the result. `N` must be an integer and defaults to zero. This simply sets bc's `scale` variable to the provided value.
\subsection return-values Return Values
@@ -33,4 +33,6 @@ If invalid options or no expression is provided the return `status` is two. If t
\subsection math-cautions Cautions
You should always place a `--` flag separator before the expression. 99.99% of the time you'll get the desired result without the separator. Something like `math -10.0 / 2` will fail because the negative floating point value gets treated as an invalid flag. But `math -10 / 2` will work because negative integers are special-cased.
Note that the modulo operator (`x % y`) is not well defined for floating point arithmetic. The `bc` command produces a nonsensical result rather than emit an error and fail in that case. It doesn't matter if the arguments are integers; e.g., `10 % 4`. You'll still get an incorrect result. Do not use the `-sN` flag with N greater than zero if you want sensible answers when using the modulo operator.