Unix Shell - Floating point math under bash

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2006 > Floating point math under bash





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Floating point math under bash
Antonio Maschio

2006-11-20, 1:18 pm

Hi,

does anyone know if there's a library (or something) that enables bash
to deal with floating point math?

Thanks in advance.

-- Antonio
sil

2006-11-20, 1:18 pm

Antonio Maschio wrote:
> Hi,
>
> does anyone know if there's a library (or something) that enables bash
> to deal with floating point math?
>
> Thanks in advance.
>
> -- Antonio


http://www.novell.com/coolsolutions/tools/17043.html

man bc

Chris F.A. Johnson

2006-11-20, 1:18 pm

On 2006-11-20, Antonio Maschio wrote:
> Hi,
>
> does anyone know if there's a library (or something) that enables bash
> to deal with floating point math?


William Park's bash extensions include RPN floating point
calculations.

<http://home.eol.ca/~parkw/index.html#bash>

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Chris F.A. Johnson

2006-11-20, 1:18 pm

On 2006-11-20, sil wrote:
> Antonio Maschio wrote:
>
> http://www.novell.com/coolsolutions/tools/17043.html
>
> man bc


I prefer awk; it's faster than bc. My calculator function is:

calc()
{
awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
}

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Antonio Maschio

2006-11-22, 7:27 am

Chris F.A. Johnson wrote:
>
> calc()
> {
> awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
> }
>


That's __exactly__ what I was looking for (silly me, I didn't think
about awk!).

Thanks everyone.

-- Antonio
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com