Re: floating-point arithmetics
From: Hans-Joachim Ehlers (service_at_metamodul.com)
Date: 08/22/03
- Next message: Stephen Baynes.: "Re: cron send mail only when an error occurs"
- Previous message: Joerg Morbitzer: "Re: [tcsh]alias taking arguments does not work"
- In reply to: Jürgen Reinecke: "floating-point arithmetics"
- Next in thread: Jürgen Reinecke: "Re: floating-point arithmetics"
- Reply: Jürgen Reinecke: "Re: floating-point arithmetics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Stephen Baynes.: "Re: cron send mail only when an error occurs"
- Previous message: Joerg Morbitzer: "Re: [tcsh]alias taking arguments does not work"
- In reply to: Jürgen Reinecke: "floating-point arithmetics"
- Next in thread: Jürgen Reinecke: "Re: floating-point arithmetics"
- Reply: Jürgen Reinecke: "Re: floating-point arithmetics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|