4.13 sed - A Stream Editor4 Labs4.11 Text processing - HTML4.12 bc -- Extended Precision Calculator

4.12 bc -- Extended Precision Calculator

  bc can compute to at least 99 places right

of the decimal point and at least 4000 to the left. This may not be fast and it may not be useful! But, it can be done. bc uses dc. dc uses reverse polish notation. It can be used from the keyboard. Most people will probably prefer bc.

If an expression does not include an assignment, the results are printed.

bc is a language as well as a desk-top calculator. The syntax

is very much like "C". With the following (and more) exceptions:

  1. No semicolon is needed at the end of a line.
  2. Variable names are only a single character.
  3. The define statement is used to define functions.

Other features of the bc program are:

bc, when invoked with the -l option,

has a limited math library. When this is used you have 6 less variable names.

It also deals with multiple bases. The input base is stored in ibase. Be cautious setting conversion bases, bc inputs ALL numbers using ibase. The output base is stored in obase. To convert 4521 from base 7 to base 13:

 
  obase = 13
  ibase = 7 
  4521 
  result returned

The fractional precision of the calculation is maintained in "scale". For example:

scale=50  

(This needs to be less than 100 on some systems.) TABER CIS137 Lab 4.12: Exercise for bc:

your name:




  1. What is 234.5*654.3/9876.5 to 12 places past the decimal point?




  2. What is 234.5*654.3/9876.5 to 12 places past the hexadecimal point?




  3. What are the first 4 digits and last 4 digits of 512^512?




  4. What happens if you use an obase of 100?




  5. If scale is set to 75, what are the last 5 digits of the sine of 1.0 radian .8414709848...........................................?????




  6. Convert 4BC4A base 13 to base 5. (Make sure that you set the output base first. If not, the new input base will be used when inputting the value for the output base.)




Turn in this page.
Instructor: Louis Taber, ltaber at uml dot lt dot Tucson dot AZ dot us (520) 206-6850
My new web Home site in Cleveland, OH
The Pima Community College web site

4.13 sed - A Stream Editor4 Labs4.11 Text processing - HTML4.12 bc -- Extended Precision Calculator