Difference between revisions of "Dc versus bc"

From Noah.org
Jump to navigationJump to search
(New page: Category:Engineering Q: What is the difference between `dc` and `bc`? A: The `dc` command is a Reverse-Polish Notation basic arithmetic calculator. It does not support common trigono...)
 
Line 5: Line 5:
 
A: The `dc` command is a Reverse-Polish Notation basic arithmetic calculator.
 
A: The `dc` command is a Reverse-Polish Notation basic arithmetic calculator.
 
It does not support common trigonometric or scientific functions.
 
It does not support common trigonometric or scientific functions.
Example of `dc`:
+
Examples of `dc`:
  
 
   $ dc -e "25.5 2 * p"
 
   $ dc -e "25.5 2 * p"
Line 15: Line 15:
  
 
The `bc` command is a front-end to `dc` (althugh the GNU `bc` is completely separate and does not compile to `dc` bytecode).  
 
The `bc` command is a front-end to `dc` (althugh the GNU `bc` is completely separate and does not compile to `dc` bytecode).  
So `bc` is similar to `dc`, but adds a C-like syntax; standard infix notation. By default it does <strong>not</strong> include trig or other common math functions, but you include these by using the '-l' option. Example of `bc`:
+
So `bc` is similar to `dc`, but adds a C-like syntax; standard infix notation. By default it does <strong>not</strong> include trig or other common math functions, but you include these by using the '-l' option. Examples of `bc`:
  
 
   $ echo "4*a(1)" | bc -l  # Note that 'a' is the arctangent function.
 
   $ echo "4*a(1)" | bc -l  # Note that 'a' is the arctangent function.

Revision as of 16:09, 3 August 2007


Q: What is the difference between `dc` and `bc`?

A: The `dc` command is a Reverse-Polish Notation basic arithmetic calculator. It does not support common trigonometric or scientific functions. Examples of `dc`:

 $ dc -e "25.5 2 * p"
 51.0
 $ dc -e "3 2 ^ p"
 9
 $ dc -e "9 v p"   # Note that 'v' is the sqrt operator.
 3

The `bc` command is a front-end to `dc` (althugh the GNU `bc` is completely separate and does not compile to `dc` bytecode). So `bc` is similar to `dc`, but adds a C-like syntax; standard infix notation. By default it does not include trig or other common math functions, but you include these by using the '-l' option. Examples of `bc`:

 $ echo "4*a(1)" | bc -l   # Note that 'a' is the arctangent function.
 3.14159265358979323844
 $ echo "scale=5; 10 / (1.5 * 2)" | bc   # Note that you have to set scale to see decimals.
 3.33333
 $ echo "10 / (1.5 * 2)" | bc   # The default scale is 0.
 3
 $ echo "10 / (1.5 * 2)" | bc -l   # Note that '-l' option automatically sets scale to 20.
 3.33333333333333333333