E
E
EvgMul2015-12-08 00:39:52
PHP
EvgMul, 2015-12-08 00:39:52

How to subtract numbers modulo?

There is the following problem: there are 2 numbers that need to be compared. They fit each other if they differ by no more than N.
I decided to do the following: I subtract these 2 numbers and look at the difference. The problem is that I do not initially know which number is greater and there is a possibility that I will get a negative number.
There are a lot of solutions, but perhaps there is a concise and harmonious solution to this problem?
By and large, you need to convert the resulting number into a positive one.
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2015-12-08
@EvgMul

By and large, you need to convert the resulting number into a positive one.

to convert a negative number to a positive there is a function abs
<?php
echo abs(-4.2); // 4.2 (double/float)
echo abs(5);    // 5 (integer)
echo abs(-5);   // 5 (integer)
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question