Answer the question
In order to leave comments, you need to log in
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
By and large, you need to convert the resulting number into a positive one.
<?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 questionAsk a Question
731 491 924 answers to any question