help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Floating point computations


From: steve-humphreys
Subject: Re: Floating point computations
Date: Tue, 20 Apr 2021 23:02:06 +0200

Would I still be able to call the mtk function as an argument to another
function?


> Sent: Wednesday, April 21, 2021 at 8:11 AM
> From: "Greg Wooledge" <greg@wooledge.org>
> To: help-bash@gnu.org
> Subject: Re: Floating point computations
>
> 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"
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]