]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
fmod.3: Add note how to obtain modulus/LPR
authorJan Engelhardt <jengelh@inai.de>
Mon, 4 Sep 2023 18:53:48 +0000 (20:53 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 13 Sep 2023 15:42:10 +0000 (17:42 +0200)
Signed-off-by: Jan Engelhardt <jengelh@inai.de>
[alx: ffix]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
man3/fmod.3

index 2eefd9d87aee774e1d7fe8469fddf4567ee1a8b9..d3973b2a7161b18d44be66ebf7950fbf2e7df991 100644 (file)
@@ -58,6 +58,23 @@ is the quotient of
 /
 .IR y ,
 rounded toward zero to an integer.
+.PP
+To obtain the modulus, more specifically, the Least Positive Residue,
+you will need to adjust the result from fmod like so:
+.PP
+.in +4n
+.nf
+z = fmod(x, y);
+if (z < 0)
+       z += y;
+.fi
+.in
+.PP
+An alternate way to express this is with
+.IR "fmod(fmod(x, y) + y, y)" ,
+but the second
+.BR fmod ()
+usually costs way more than the one branch.
 .SH RETURN VALUE
 On success, these
 functions return the value \fIx\fP\ \-\ \fIn\fP*\fIy\fP,