[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Floating point computations
From: |
Greg Wooledge |
Subject: |
Re: Floating point computations |
Date: |
Tue, 20 Apr 2021 16:11:31 -0400 |
On Tue, Apr 20, 2021 at 10:07:40PM +0200, steve-humphreys@gmx.com wrote:
> Want to use a function for doing mathematical computations as
> follows.
>
> mtk ()
> {
> s=`echo "$@" | bc -l`
> echo "$s"
> }
>
> $(mtk "15.6+299.33*2.3/7.4")
> $(mtk "scale=5; 15.6+299.33*2.3/7.4")
1) Do not call the function inside a command substitution. Instead of
$(myfunc)
just call
myfunc
2) You don't need to capture the output in a variable and then write the
contents of the variable, Just let bc write directly to stdout. Step
out of its way. Let it do what it does.
mtk() {
echo "$*" | bc -l
}
mtk "15.6+299.33*2.3/7.4"