Questions tagged [bc]
Arbitrary-precision arithmetic language.
122 questions
2 votes
1 answer
264 views
bc inconsistent trailing zero result as part of a bash script variable
Consider: heightScaled=$(bc <<< $H*$S/1) echo $heightScaled 45.0 Why am I getting 45.0 despite the same operations yielding 45 if used outside the script either interactively or piped into ...
0 votes
2 answers
113 views
Can bc explain itself instead of just giving you an answer?
When you do math in bc it clearly uses some order of operations. And I know that this falls within the realm of Reverse Polish Notation; so is it possible for it to explain itself? I mean I know I can ...
4 votes
1 answer
303 views
using the bc calculator with obase and ibase to convert integer representation
I am using the bc calculator with obase and ibase to convert integer representation. I'm not used to it, because very basic things can be done with $(( expresion )) in bash, and most things that can't ...
-2 votes
1 answer
360 views
Why does bc not have easy to use built in support for rounding? [closed]
I just wrote a small bash shell script and for the first time in that context I wanted to make a calculation, a division, and discovered bc. My script processes media files and I want to log the ...
-2 votes
2 answers
244 views
How to make bc handle explicitly positive numbers? Or what alternative calculator can be used with such support?
Consider the following: $ echo "-1" | bc -1 $ echo "(1)" | bc 1 $ echo "+1" | bc (standard_in) 1: syntax error Minus sign and round braces are handled correctly but ...
1 vote
1 answer
87 views
Why does "bc" read my config file on one computer and not another?
I have two old machines, running CentOS 6.5 and CentOS 6.10. Both have bc 1.06.95-1.el6 installed. One reads $HOME/.bc.rc, one does not. Why ? (How??) strace shows near-identical output, except one ...
2 votes
1 answer
131 views
Use m4 interactively with bc
I would like to use m4 interactively as a preprocessor for bc. My immediate use case is to add an include capability to bc, but I can foresee other uses in the future. But there is a problem. Here is ...
0 votes
3 answers
190 views
bash array multiplication using bc
I am trying to multiply array values with values derived from the multiplication of a loop index using bc. #!/bin/bash n=10.0 bw=(1e-3 2.5e-4 1.11e-4 6.25e-5 4.0e-5 2.78e-5 2.04e-5 1.56e-5 1.29e-5 1....
3 votes
1 answer
367 views
By default, bc interprets any alpha character as a 9
System: Ubuntu 22.04.3 LTS GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) bc 1.07.1 Observation: Both ibase and obase are unset. echo "A0" | bc 90 echo "B0" | bc 90 ...
0 votes
0 answers
71 views
is it possible to integrate bc calculator in an app (script interpreter) as a library?
is it possible to integrate bc command line calculator in an app (script interpreter) as a library? I am not asking if that can be done, I am asking if there is something ready already that wraps bc ...
1 vote
1 answer
250 views
Why I can pipe echo into bc, but I can't do the same with printf?
I can pipe echo into bc. But I cannot do the same with "printf": it gives syntax error. ❯ echo "100-5" | bc 95 ❯ printf "%s" "100-5" | bc (standard_in) 1: ...
1 vote
1 answer
4k views
(standard-in) 1: Syntax error when using bc
I have this command that works correct. However it shows a (standard_in) 1: Syntax error that I don't know how to identify. participants=0 while IFS=, read -r id name nat sex date height weight sport ...
1 vote
2 answers
218 views
What's the upper-bound for an array index/subscript in GNU bc?
I've found that there is an upper-bound on your subscripts/indices in an array in GNU bc. Running interactively and asking to let arr[100000000]=42 returns an error: Runtime error (func=(main), adr=...
10 votes
3 answers
5k views
Linux bc defines PI as 99
I'm using bc in Ubuntu Linux. It has a pre-defined constant PI that's set to 99. Why does bc define PI to be 99 instead of 3.14159...?
2 votes
0 answers
111 views
bash variable getting some weird hex data from Command substitution calling a script containing a bc calculation
bash --version GNU bash, version 5.1.16(1)-release (x86_64-apple-darwin21.1.0) I'm calling a script (dewpoint) which contains a bc calculation that defines dewpoint based on temp(c) and humidity(%). ...