All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR
@ 2023-07-24 13:49 Jan Engelhardt
  2023-07-24 13:49 ` [PATCH 2/2] fmod.3: add example section Jan Engelhardt
  2023-07-28 20:26 ` [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Alejandro Colomar
  0 siblings, 2 replies; 6+ messages in thread
From: Jan Engelhardt @ 2023-07-24 13:49 UTC (permalink / raw)
  To: alx; +Cc: linux-man

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

diff --git a/man3/fmod.3 b/man3/fmod.3
index ee2333fdc..a33b83eb5 100644
--- a/man3/fmod.3
+++ b/man3/fmod.3
@@ -58,6 +58,9 @@ is the quotient of
 /
 .IR y ,
 rounded toward zero to an integer.
+.PP
+To obtain the modulus, more specifically, the Least Positive Residue, the
+expression "fmod(fmod(x, y) + y, y)" needs to be used.
 .SH RETURN VALUE
 On success, these
 functions return the value \fIx\fP\ \-\ \fIn\fP*\fIy\fP,
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] fmod.3: add example section
  2023-07-24 13:49 [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Jan Engelhardt
@ 2023-07-24 13:49 ` Jan Engelhardt
  2023-07-28 20:26 ` [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Alejandro Colomar
  1 sibling, 0 replies; 6+ messages in thread
From: Jan Engelhardt @ 2023-07-24 13:49 UTC (permalink / raw)
  To: alx; +Cc: linux-man

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

diff --git a/man3/fmod.3 b/man3/fmod.3
index a33b83eb5..2650d2928 100644
--- a/man3/fmod.3
+++ b/man3/fmod.3
@@ -154,5 +154,11 @@ to
 .B EDOM
 when a domain error occurred for an infinite
 .IR x .
+.SH EXAMPLES
+The call "fmod(372, 360)" returns 348.
+.PP
+The call "fmod(-372, 360)" returns -12.
+.PP
+The call "fmod(-372, -360)" also returns -12.
 .SH SEE ALSO
 .BR remainder (3)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR
  2023-07-24 13:49 [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Jan Engelhardt
  2023-07-24 13:49 ` [PATCH 2/2] fmod.3: add example section Jan Engelhardt
@ 2023-07-28 20:26 ` Alejandro Colomar
  2023-09-04 18:53   ` [PATCH v2 " Jan Engelhardt
  1 sibling, 1 reply; 6+ messages in thread
From: Alejandro Colomar @ 2023-07-28 20:26 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: linux-man


[-- Attachment #1.1: Type: text/plain, Size: 1054 bytes --]

Hi Jan,

On 2023-07-24 15:49, Jan Engelhardt wrote:
> Signed-off-by: Jan Engelhardt <jengelh@inai.de>
> ---
>  man3/fmod.3 | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/man3/fmod.3 b/man3/fmod.3
> index ee2333fdc..a33b83eb5 100644
> --- a/man3/fmod.3
> +++ b/man3/fmod.3
> @@ -58,6 +58,9 @@ is the quotient of
>  /
>  .IR y ,
>  rounded toward zero to an integer.
> +.PP
> +To obtain the modulus, more specifically, the Least Positive Residue, the
> +expression "fmod(fmod(x, y) + y, y)" needs to be used.

There's a more readable way (and it's probably also more efficient):
<https://stackoverflow.com/a/2708900>

I think it would be interesting to have an example program that
shows both, and implements a function double lpr(double, double)
that uses the branchy implementation.

Thanks,
Alex

>  .SH RETURN VALUE
>  On success, these
>  functions return the value \fIx\fP\ \-\ \fIn\fP*\fIy\fP,

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] fmod.3: add note how to obtain modulus/LPR
  2023-07-28 20:26 ` [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Alejandro Colomar
@ 2023-09-04 18:53   ` Jan Engelhardt
  2023-09-04 18:53     ` [PATCH v2 2/2] fmod.3: add example section Jan Engelhardt
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Engelhardt @ 2023-09-04 18:53 UTC (permalink / raw)
  To: alx; +Cc: linux-man

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] fmod.3: add example section
  2023-09-04 18:53   ` [PATCH v2 " Jan Engelhardt
@ 2023-09-04 18:53     ` Jan Engelhardt
  2023-09-13 16:00       ` Alejandro Colomar
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Engelhardt @ 2023-09-04 18:53 UTC (permalink / raw)
  To: alx; +Cc: linux-man

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

diff --git a/man3/fmod.3 b/man3/fmod.3
index 944bf4167..13236c425 100644
--- a/man3/fmod.3
+++ b/man3/fmod.3
@@ -165,5 +165,11 @@ to
 .B EDOM
 when a domain error occurred for an infinite
 .IR x .
+.SH EXAMPLES
+The call "fmod(372, 360)" returns 348.
+.PP
+The call "fmod(-372, 360)" returns -12.
+.PP
+The call "fmod(-372, -360)" also returns -12.
 .SH SEE ALSO
 .BR remainder (3)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] fmod.3: add example section
  2023-09-04 18:53     ` [PATCH v2 2/2] fmod.3: add example section Jan Engelhardt
@ 2023-09-13 16:00       ` Alejandro Colomar
  0 siblings, 0 replies; 6+ messages in thread
From: Alejandro Colomar @ 2023-09-13 16:00 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: linux-man


[-- Attachment #1.1: Type: text/plain, Size: 759 bytes --]

Hi Jan,

On 2023-09-04 20:53, Jan Engelhardt wrote:
> Signed-off-by: Jan Engelhardt <jengelh@inai.de>

Patch set applied.

Thanks,
Alex

> ---
>  man3/fmod.3 | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/man3/fmod.3 b/man3/fmod.3
> index 944bf4167..13236c425 100644
> --- a/man3/fmod.3
> +++ b/man3/fmod.3
> @@ -165,5 +165,11 @@ to
>  .B EDOM
>  when a domain error occurred for an infinite
>  .IR x .
> +.SH EXAMPLES
> +The call "fmod(372, 360)" returns 348.
> +.PP
> +The call "fmod(-372, 360)" returns -12.
> +.PP
> +The call "fmod(-372, -360)" also returns -12.
>  .SH SEE ALSO
>  .BR remainder (3)

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-13 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-24 13:49 [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Jan Engelhardt
2023-07-24 13:49 ` [PATCH 2/2] fmod.3: add example section Jan Engelhardt
2023-07-28 20:26 ` [PATCH 1/2] fmod.3: add note how to obtain modulus/LPR Alejandro Colomar
2023-09-04 18:53   ` [PATCH v2 " Jan Engelhardt
2023-09-04 18:53     ` [PATCH v2 2/2] fmod.3: add example section Jan Engelhardt
2023-09-13 16:00       ` Alejandro Colomar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.