[PATCH v2 1/2] fmod.3: add note how to obtain modulus/LPR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jan Engelhardt <jengelh@xxxxxxx>
---
 man3/fmod.3 | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/man3/fmod.3 b/man3/fmod.3
index ee2333fdc..944bf4167 100644
--- a/man3/fmod.3
+++ b/man3/fmod.3
@@ -58,6 +58,20 @@ 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
+.RS 4
+.nf
+z = fmod(x, y);
+if (z < 0)
+	z += y;
+.fi
+.RE
+.PP
+An alternate way to express this is with "fmod(fmod(x, y) + y, y)", but the
+second 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,
-- 
2.42.0




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux