MPE/iX Shell and Utilities Reference Manual, Vol 1

bc(1) MPE/iX Shell and Utilities bc(1)
This is a very useful function if you want to work with monetary values. For example, you
can now rewrite sales_tax() to use round2().
define sales_tax(purchase,tax) {
auto old_scale
scale = 2
tax = round2(purchase*(tax/100))
scale = old_scale
return (tax)
}
Here is a function which recursively calculates the factorial of its argument.
define fact (x) {
if(x < 1) return 1
return (x*fact(x-1))
}
The factorial function can also be written iteratively as:
define fact (x) {
auto result
result = 1
while(x>1) result *= x--
return (result)
}
With either version, fact(6) returns 720.
Here is another recursive function. This one calculates the nth element of the Fibonacci
sequence.
define fib(n) {
if(n<3){
return (1)
} else {
return (fib(n-1)+fib(n-2))
}
}
1-62 Commands and Utilities