The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
2answers
39 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 ...
1
vote
1answer
9 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 ...
2
votes
1answer
91 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 ...
1
vote
2answers
966 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
515 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
1answer
111 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
3
votes
4answers
2k 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, ...
4
votes
3answers
5k 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