K
K
ksvdon2014-10-29 12:30:18
bash
ksvdon, 2014-10-29 12:30:18

How to compare numbers modulo in bash?

There are 2 numbers. There may be a slight difference between these numbers. I want to compare these numbers with tolerance. Let's say 10 and 13 have a tolerance of 5. "10 - 13 = -3" should look like "-3" is less than "5" in absolute value. I don't know if it's possible to look at numbers modulo in bash? Can bc do this or is it somehow possible?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Lerg, 2014-10-29
@ksvdon

Try
${VAR#-}

J
jcmvbkbc, 2014-10-29
@jcmvbkbc

expand the module into two conditions.

Z
Zr, 2014-11-05
@Zr

No, in my opinion, the Bash module is not able to take. But the square can:

$ a=10
$ b=13
$ delta=5
$ (((a-b)**2 <= delta**2)) && echo 'OK'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question