Re: floating-point arithmetics

From: Hans-Joachim Ehlers (service_at_metamodul.com)
Date: 08/22/03


Date: Fri, 22 Aug 2003 13:19:17 +0200


"Jürgen Reinecke" <jgreinecke@web.de> schrieb im Newsbeitrag
news:3F45ED79.C7588277@web.de...
> Hello all,
>
>
> simply would like to know what options or commands to use when I
> need floating point arithmetics, and the syntax of non-integer.
>
> For example how would I make the area calculator below work?
> function area () {
> let pi=3,14
> let "res = pi * $1 * $1"
> return $res
> }

Example for a simple BC calculation

#!/bin/ksh
export LANG=C
# functions
area () {
pi=3.1415
res=$( echo "scale=99; $pi*$1*$2" | bc )
echo "$res"
return 0
}
# main
area 0.001 0.2 | read A
echo "$A"

>
> From everything I read so the shell is limited to integer
> arithmetics; the only thing I found was the 'bc' command.
>
> However 'man bc' left me completely confused... it's a
> real programming language rather than some simple-to-use
> calculator... do I need to find a tutorial on that or are there
> other ways?

If you wanna go deeper you should look for a "bc" tutorial.
Also i do not know how far "awk" is able to do precise calculations.

HTH
Hajo
CATE RS/6000



Relevant Pages

  • Re: [opensuse] Command line calculator?
    ... line calculator, and if so what it is called? ... echo $) ... (BASH has this, ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: what about now? [ADD == --]
    ... You posted TWO programs which show COMMANDS REVERSED in one of them. ... Logic would suggest that both versions should not compile the same, ... calculator, then regardless of how the flag is set, the editor would ... and can even be used within algebraic objects, as also can -NEGin algebraics ...
    (comp.sys.hp48)
  • Re: [opensuse] Command line calculator?
    ... On Friday 29 June 2007 12:58, G T Smith wrote: ... calculator, and if so what it is called? ... echo $) ... (BASH has this, too, perhaps even better, being ...
    (SuSE)
  • Re: Technology brief on extensions in MorphEngine
    ... case of one new calculator architecture, ... running on a new platform, to support some of UserRPL, ... and ENDSUB commands for DOSUBS, ... Australia would in fact be a lovely place to be right now, ...
    (comp.sys.hp48)
  • Re: Is it a bug or my misunderstanding?
    ... while the calculator is in exact mode. ... "Exact" mode primarily affects the original interpretation ... Some commands, particularly those which existed before any CAS, ...
    (comp.sys.hp48)