help-bash
[Top][All Lists]
Advanced

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

Re: Kludge for handling REPL arithmetic expressions


From: David
Subject: Re: Kludge for handling REPL arithmetic expressions
Date: Tue, 3 Aug 2021 15:43:11 +1000

On Tue, 3 Aug 2021 at 15:34, David <bouncingcats@gmail.com> wrote:
> On Tue, 3 Aug 2021 at 13:32, Eric Pruitt <eric.pruitt@gmail.com> wrote:

> I imagine it's readily achievable.
> In the function, I would detect three cases:
>   either "$1" == '=' or "$1" == =* or neither.
> Then for both the matches, use some method to remove the "=",
> ie discard the whole $1 or discard just its first character, as required.
> Then use arithmetic context $(( ... )) to evaluate the rest of the
> arguments, then printf the result.

That will do integer arithmetic. If you want floating point,
you will need to do the same preprocessing and then pass
the args to whatever calculation backend you are using
already, instead of using Bash arithmetic context which is
integer-only, ie 2/3 = 0.



reply via email to

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