Commit Graph

12 Commits

Author SHA1 Message Date
ridiculousfish
d2bee105c9 Default math scale to 6
This changes the behavior of builtin math to floating point by default.
If the result of a computation is an integer, then it will be printed as an
integer; otherwise it will be printed as a floating point decimal with up to
'scale' digits past the decimal point (default is 6, matching printf).
Trailing zeros are trimmed. Values are rounded following printf semantics.

Fixes #4478
2018-08-04 15:32:09 -07:00
Fabian Homborg
2d08b5ee8a [math] Add tests for runtime errors
And fix "isinfinite" - it's called "isinf".
2018-03-07 18:13:26 +01:00
Fabian Homborg
0da8022081 [math] Fail without arguments
See #4768.
2018-03-01 22:27:24 +01:00
Fabian Homborg
f60e1549a9 [math] Better error for 2 + 2 4
This now reports "TOO_MANY_ARGS" instead of no error (and triggering
an assertion).

We might want to add a new error type or report the missing operator
before, but this is okay for now.
2018-03-01 13:09:35 +01:00
Fabian Homborg
20af969aba [math] Adjust tests for new error reporting
This shows how it's still weird - "2 - " and "max()" return the same
error.
2018-03-01 13:09:35 +01:00
ridiculousfish
67a6f756f2 Add some math tests for invalid inputs 2017-12-18 23:01:16 -08:00
ridiculousfish
81dd4a4536 [math] Remove more bare variable support
Prior to this fix, a "bare variable" in math like 'x + 1' would be
looked up in the environment, i.e. equivalent to '$x + 1'. This appears
to have been done for performance. However this breaks the orthogonality
of fish; performance is not a sufficient justification to give math this
level of built-in power, especially because the performance of math is
not a bottleneck. The implementation is also ugly.

Remove this feature so that variables must be prefixed with the dollar
sign and undergo normal variable expansion. Reading 'git grep' output
does not show any uses of this in fish functions or completions.

Also added to changelog.

Fixes #4393
2017-12-17 12:40:09 -08:00
Kurtis Rader
c95b9f06e1 Implement support for bare vars by math
This change allows you to type `math x + 3` rather than `math $x + 3`.

Another step to resolving issue #3157.
2017-08-23 20:41:45 -07:00
Kurtis Rader
d10decabda Make builtin math the default implementation
Remove our `math` function that wraps `bc`. Our math builtin is now good
enough that it can be the default implementation.

Another step in resolving #3157.
2017-08-23 17:32:49 -07:00
Kurtis Rader
98449fec51 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.
2017-07-14 16:03:31 -07:00
Fabian Homborg
7ffcb828fe Add test for long numbers in math
This should catch the error in 26e781ef5a.
2016-12-29 14:00:15 +01:00
Kurtis Rader
d97c22df2d add floating point output to math command
This makes it easy for the user to request floating point output with the
desired number of digits after the decimal point (not to be confused with
significant digits).

Note that this is just a thin wrapper so someone can say `math -s3 10 / 3`
rather than `math "scale=3; 10 /3"`.

Resolves #1643
2016-05-03 19:29:04 -07:00