Questions tagged [bc]
"Basic Calculator," an arbitrary-precision calculator language. General bc questions are a better fit for unix.stackexchange.com, while "programming" questions about bc fit on stackoverflow.com.
15 questions
-3
votes
1
answer
92
views
bc command results are not what are expected when changing from ibase to obase
I am trying to convert non-base 10 (non-decimal) numbers to each other by using bc command in Linux, but the answers are different from what I expected.
ibase = 3
obase = 7
23
11
Why is the answer 11?...
0
votes
2
answers
3k
views
Using variables with bc: syntax error
The original problem
This may be more of a bc or bash question than an FFmpeg one, although I would also appreciate being able to prevent ffprobe from printing carriage returns after its output.
In a ...
0
votes
2
answers
2k
views
Powershell: evaluate math expression represented as string
In PowerShell, how do I evaluate a mathematical expression stored as a string? How do I get PowerShell to evaluate the following:
C:\> $a="30000/1001"
C:\> $a
30000/1000
C:\>
Desired output:...
1
vote
2
answers
830
views
Why isn't my Bash script returning the correct answer to this Project Euler?
I'm trying to use Bash to complete Project Euler 13. Below is my code that I just cannot figure out what's wrong with.
#!/bin/bash
sum=0 ...
2
votes
1
answer
481
views
How to tell bash to repeat a script until satisfactory, then output the finished product
I'm looking to repeat this code until I stop it, either by setting a time for which it repeats, pressing ^c, or set number of iterations, and then output the result of repeating it. The code should ...
0
votes
1
answer
86
views
Substarct two float numbers in shell script
I have written shell script to substract two float values
For eg. below are the two values :
debit_amount=7.853117806000353E7
credit_amount=3223649.619999993
val1=$(printf "%f", "$debit_amount")
...
0
votes
1
answer
189
views
Particular bash bc usage not storing result in variable
Unfortunately this result in a empty variable, and bc command print its result to terminal anyway while trying to attribute to aux
aux=&(bc -l <<< "scale = 5; c(${arguments[0]}*$constant)...
1
vote
2
answers
419
views
Wrong results when comparing two numbers with bc (bash)
I’ve encountered an error, probably a bug in bc. I encountered it when trying to compare two numbers on a script in bash. It turns out that when I do:
echo "1.1E-2<1.1E-1" | bc -l
It returns 1 (as ...
2
votes
3
answers
1k
views
Get GNU bc to print a newline character
GNU bc is very unconventional. I can't find anything online about how to get it to print a newline character. I'm trying to get it to print the first 16 hexadecimal digits of the sines of the integers ...
5
votes
1
answer
352
views
Why is `bc` ignoring my `obase`?
>>> bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
ibase = 16
obase = 56
...
20
votes
3
answers
22k
views
How to do division with bc (bench calculator) and obtain fractional results?
bc
1/2
0
5/3
1
10/3
3
When a fraction is entered into bc, the result is truncated to an integer. How can this behavior be avoided, such that the output of a division operation is a real number?
0
votes
1
answer
894
views
Best floating point solution for bash script?
I use bash calculator for floating point calculations and I have to use input redirection and backtick (`) symbol in scripts.
As normal bracket $[math operation] and expr doesn't support float ...
1
vote
1
answer
156
views
Multiplication in bc (bench calculator)
$ echo 2*1024|bc
20480
$ echo 2.0*1024|bc
2048.0
$ echo 2*1024.0|bc
2048.0
What's going on here then?
Update:
dc manages fine
$ echo "2 1024 * p"|dc
2048
5
votes
4
answers
3k
views
Dividing with Gnu's bc
I'm just starting with Gnu's bc and I'm stuck at the very beginning (very discouraging...). I want to divide two numbers and get a float as result:
$bc
bc 1.06.94
Copyright 1991-1994, 1997, 1998, ...
16
votes
5
answers
23k
views
GNU BC: "modulo" % with scale other than 0
If the scale is other than zero, calculations with %, such as 3%2 and 46%4, tend to output 0. How is the algorithm designed with the scale other than 0?
bc
scale=10
print 4%3 // output 0