in reply to Simple command line calculator


On Unix there is also the bc(1) utility which performs arbitrary precision arithmetic.
$ bc 1 + 3 4 2^4 16 123456789012345678901234567890 * 2 246913578024691357802469135780 ibase=16 FF 255 quit

Remember kids, Unix isn't just there to start perl, it has a few other uses as well. ;-)

--
John.

Replies are listed 'Best First'.
Re: Re: Simple command line calculator
by mr_mischief (Monsignor) on Mar 26, 2002 at 19:34 UTC
    It doesn't do floating point, though, which is why I often do use perl in non-debugging interactive mode or use a one-liner.
    perl -e 'print 5/2, "\n"';
    I like getting `2.5' there instead of just `2'.

    Or, just do this:
    # perl
    
    which will let you type a program into STDIN for perl to execute. Perfect if you need to make three or four calculations.

      It doesn't do floating point, though

      It does do floating point. Although, by default bc shows the results of calculations as integers. However, that can be changed either by setting scale or by invoking it with the -l option:

      $ bc 5/2 2 scale=4 5/2 2.5000 $ bc -l 5/2 2.50000000000000000000

      --
      John.