mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
math: Set BC_LINE_LENGTH to a very high number
This means we no longer have to do manual stitching which improves performance.
This commit is contained in:
parent
7ffcb828fe
commit
b29b026106
1 changed files with 6 additions and 3 deletions
|
@ -21,9 +21,12 @@ function math --description "Perform math calculations in bc"
|
||||||
return 2 # no arguments is an error
|
return 2 # no arguments is an error
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stitch lines together manually. We can't rely on BC_LINE_LENGTH because some systems don't
|
# Set BC_LINE_LENGTH to a ridiculously high number so it only uses one line for most results.
|
||||||
# have a new enough version of bc.
|
# Results with more digits than that are basically never used anyway.
|
||||||
set -l out (echo "scale=$scale; $argv" | bc | string replace -r '\\\\$' '' | string join '')
|
# We can't use 0 since some systems (including macOS) use an ancient bc that doesn't support it.
|
||||||
|
# 32767 should still work on 2-byte int systems, though this is untested.
|
||||||
|
set -lx BC_LINE_LENGTH 32767
|
||||||
|
set -l out (echo "scale=$scale; $argv" | bc)
|
||||||
switch "$out"
|
switch "$out"
|
||||||
case ''
|
case ''
|
||||||
# No output indicates an error occurred.
|
# No output indicates an error occurred.
|
||||||
|
|
Loading…
Reference in a new issue