The bc tag has no wiki summary.
1
vote
2answers
41 views
Division with bc (bench calculator)
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 ...
0
votes
1answer
37 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 ...
0
votes
0answers
41 views
bc's scale and calc comparison
Do you have a better way of changing bc's default scale than below?
in ~/.bashrc add
BC_ENV_ARGS=~/.bc
export BC_ENV_ARGS
then in ~/.bc:
scale=2
By the way, do you have any preference between ...
1
vote
1answer
58 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
0
votes
1answer
297 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, ...
0
votes
1answer
2k 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
1
vote
1answer
53 views
GNU BC: functions, if-clauses and returns
The questions are in the comments of the code:
define f(x) {
print x^2
}
define g(x) {
print x+2
}
if(f(2)>g(1)) {
print "it works"
}
43 # Why 43 instead of the text "it works"?
a=f(2)
...