I’m wondering about it’s application though. Does it go by another name?
avencherus | 2017-01-25 08:52
Mathematically, the function that returns -7 is called the Remainder function (Rem) and the function that returns 3 is called the Modulus function (Mod). It’s more common to implement the Remainer instead of the Modulus as it is easier to write and works fast for positive values.
To answer this old post, it is useful for wrapping numbers in a positive or negative direction. Modulus wraps in the positive direction only.
I had an issue understanding it, because the old implementation was wrong. It has since been fixed.
As an example, looping backwards through an array, but wanting to wrap back to the end.
[0, 1, 2, 3, 4]
If at index 0, and subtracting 1, it would go to index -1. With that index and the array size of 5, fposmod(-1, 5) would return 4, wrapping back to the end of that array while travelling in the negative direction.