#9 An Arbitrary-Precision Floating-Point Calculator

One of the most commonly used sequences in script writing is $(( )), which lets you perform calculations using various rudimentary mathematical functions. This sequence can be quite useful, most commonly when incrementing counter variables, and it supports addition, subtraction, division, remainder, and multiplication, though not any sort of fractional or decimal value. Thus, the following command returns 0, not 0.5:

echo $(( 1 / 2 ))

So when calculating values that need better precision, you've got a challenge on your hands. There just aren't many good calculator programs that work on the command line. Except, that is, for bc, an oddball program that few Unix people are taught. Billing ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.