bc

So, I just discovered the Unix tool bc.  Given that I’m a Mac guy as much for the Unix as for anything else, this got me interested.

bc is a mathematical programming language and interactive calculator.  The latter is useful, sometimes I need a calculator, and for what I’m doing that instant, a terminal app is most appropriate.  bc fills that role well.

bc also is a C like programming language for mathematical operations.  I haven’t gotten deeply into it, but here’s a factorial function, with a simple recursive implementation.  

/*Factorial function in bc*/

define fact(x)

{

    if( x <= 1){

        return 1

    }else{

        return x * fact(x-1)

    }

}

Advertisements