Is it possible to calculate the remainder of two given values with merely addition, subtraction, multiplication, and division? Is there an algorithm or formula if it is even possible?
For instance, say we have two values: 100
and 30
. If we divide 100
by 30
, we get 3.333...
. But is there any way to reach 0.333...
(without knowing from the get go how many wholes are included)?
To further illustrate what I mean, and sticking with the example above, one way to find the remainder would be the following formula: 100 / 30 / 10 * 30 = 0.333...
BUT this obviously does not work for any two given numbers.
Some more examples (The values in the brackets are the values I am after):
100 / 40 = 2.5 (0.5)
450 / 50 = 9 (0)
11 / 4 = 2.75 (75)
Sorry, if this question is not clear. It is based on a programming challenge I have encountered. I want to use only CSS to calculate the remainder of a text's line height, given a specific vertical offset of the text. For instance, the height of the window might be 100
, whereas the line height would be 30
. But CSS has no function to easily determine the remainder, and I cannot use loops or recursion (i.e. 100 - 30 - 30 - 30 - 30 < 0
), nor conditional (i.e. if N
< 0
, do...).
My math is awful. But I am wondering whether or not it is mathematically possible?
:nth-child()
and:first-child
to perform the modular arithmetic. $\endgroup$ – Eric Towers Oct 28 '20 at 19:05