Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)

User Commands (a - b) bc(1)
Enter:
bc -l prog.bc
This statement interprets the bc program saved in prog.bc, then reads more bc command
statements from standard input (the keyboard). Starting the bc command with the -l flag
makes the math library available. This example uses the e (exponential) function from
the math library, and f is defined in the program prog.bc.
Enter:
e(2) /* e squared */
The system responds as follows:
7.38905609893065022723
Enter:
f(5) /* 5 factorial */
The system responds as follows:
120
Enter:
f(10) /* 10 factorial */
The system responds as follows:
3628800
4. To convert an infix expression to Reverse Polish Notation (RPN), enter:
Enter:
bc -c
(a*b)%(3+4*c)
The system responds as follows:
lalb* 3 4lc*+%ps.
This statement compiles the bc infix-notation expression into an expression that the dc
command can interpret. dc evaluates extended RPN expressions. In the compiled out-
put, the lowercase l before each variable name is the dc subcommand to load the value of
the variable onto the stack. The p displays the value on top of the stack, and the s. dis-
cards the top value by storing it in register . (dot). You can save the RPN expression in a
file for dc to evaluate later by redirecting the standard output of this command.
FILES
/usr/lib/lib.b Mathematical library.
/bin/dc Desk calculator proper; uses bc as preprocessor.
RELATED INFORMATION
Commands: dc(1).
527188-021 Hewlett-Packard Company 135