[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: REQUEST - bash floating point math support
From: |
Greg Wooledge |
Subject: |
Re: REQUEST - bash floating point math support |
Date: |
Wed, 5 Jun 2024 14:11:32 -0400 |
On Wed, Jun 05, 2024 at 01:31:20PM -0400, Saint Michael wrote:
> the most obvious use of floating variables would be to compare
> balances and to branch based on if a balance is lower than a certain
> value
> I use:
> t=$(python3 -c "import math;print($balance > 0)")
> and the
> if [ "$t" == "False" ];then
> echo "Result <= 0 [$t] Client $clname $clid Balance $balance"
> fi
> There must be a solution without Awk or Python or BC. Internal to bash
The example you show is just comparing to 0, which is trivial. If
the $balance variable begins with "-" then it's negative. If it's "0"
then it's zero. Otherwise it's positive.
For comparing two arbitrary variables which contain strings representing
floating point numbers, you're correct -- awk or bc would be the minimal
solution.
- Re: REQUEST - bash floating point math support, (continued)
- Re: REQUEST - bash floating point math support, Chet Ramey, 2024/06/21
- Re: REQUEST - bash floating point math support, Chet Ramey, 2024/06/12
- Re: REQUEST - bash floating point math support, Robert Elz, 2024/06/05
- Re: REQUEST - bash floating point math support, Greg Wooledge, 2024/06/05
- Re: REQUEST - bash floating point math support, Léa Gris, 2024/06/06
- Re: REQUEST - bash floating point math support, Robert Elz, 2024/06/05
- Re: REQUEST - bash floating point math support, Saint Michael, 2024/06/05
- Re: REQUEST - bash floating point math support,
Greg Wooledge <=
- Re: REQUEST - bash floating point math support, Saint Michael, 2024/06/05
- Re: REQUEST - bash floating point math support, Robert Elz, 2024/06/05
- Re: REQUEST - bash floating point math support, Zachary Santer, 2024/06/06