The bc tag has no wiki summary.
4
votes
1answer
27 views
BC not handling scale = 0 correctly
I defined the cbrt function to return a cube root. I need to get an integer back (even if it is close to the cube root, it will be acceptable in my case). However, when I put the scale as 0 to get an ...
2
votes
2answers
40 views
BC—automatic full precision multiplication
High, I need to test my arbitrary precision calculator, and bc seems like a nice yardstick to compare to, however, bc does truncate the result of each multiplication to what seems to be the maximum ...
2
votes
4answers
386 views
Perform floating point arithmetic in shell script variable definitions
I understand bash and some other interpreters only perform arithmetic for integers. In the following for loop, how can I accomplish this? I've read that bc can be used but am not sure how to use bc ...
2
votes
2answers
221 views
Float operation with bc?
It looks like bc doesn't support float operations, when I do echo 1/8 | bc it get me a zero.
I checked bc (1), but it doesn't even mention float, so I wonder if it's supported?
3
votes
4answers
196 views
Round/truncate digit in string in zsh (or with external tool)
I'm trying to do an interface to bc so it can be used intuitively and without the annoyance of getting "stuck" in it. I haven't got around to test it that much, because I got stuck on another detail, ...
2
votes
3answers
723 views
How can I call bc from within awk in this case?
OK, so I love my awk, but yeah, it has precision issues, and unfortunately there's no easy way for me to install the multi-precision extensions known as gawkextlib.
What I am doing is, I am working ...
2
votes
4answers
1k views
Calculate variable, and output it to another variable
The only calculator I know is bc. I want to add 1 to a variable, and output to another variable.
I got the nextnum variable from counting string in a file:
nextnum=`grep -o stringtocount ...
5
votes
2answers
752 views
Does bc supports hex calculations?
I'm trying to do a hex calculation directly with bc, I already specified the scale.
echo 'scale=16;c06b1000-c06a5e78' | bc
But it still got me zero. What could be wrong?
4
votes
1answer
280 views
How to define a `bc` function for later use?
I've always found bc kind of mysterious and intriguing. It was one of the original Unix programs. And it's a programming language unto itself. So I gladly take any chance I can find to use it.
Since ...
2
votes
2answers
447 views
How to divide a list of values by a number in command line?
I am trying to translate a simple program to the command line using unix utilities. For example, if I have a frequency list (after piping through uniq and sort)
5 x
4 y
1 z
I want to print out, ...
7
votes
7answers
1k views
Doing simple math on the command line using bash functions: $1 divided by $2 (using bc perhaps)
Sometimes I need to divide one number by another. It would be great if I could just define a bash function for this. So far, I am forced to use expressions like
echo 'scale=25;65320/670' | bc
but ...
3
votes
3answers
4k views
How to calculate values in a shell script?
I run this command in the terminal:
grep "bla bla blah" blah* | echo "Blah: $(wc -l) / $(ls | wc -l) * 100"
And I get this output:
Blah: 44 / 89 * 100
What I expect to see:
49.4
Is there a ...
2
votes
3answers
804 views
Syntax error comparing floats with bc
I'm trying to use the comparison operator of bc and I'm getting a "syntax error on line 1 stdin" error. I need to use the comparison functionality within a korn script because korn doesn't handle ...
13
votes
6answers
19k views
Is there a way to get the min, max, median, and average of a list of numbers in a single command?
I have a list of numbers in a file, one per line. How can I get the minimum, maximum, median and average values? I want to use the results in a bash script.
Although my immediate situation is for ...
3
votes
1answer
274 views
BC - output normal form?
I have a big number:
2923174917395723957
that would be:
2,923*10^18
are there any parameters in bc that will give this OUTPUT?
e.g.:
$ echo '2923174917395723956 + 1' | bc
2,923*10^18
$
Or ...
2
votes
4answers
356 views
BC - no “\\n” at the end + start with zeros?
This is a bc output, e.g.:
Input:
echo "scale=10; BLA-BLA-HERE-NOT-IMPORTANT" | bc
Output:
.3708446283953709207058828124021300754352578903651372655882743141882\
...