Hi Morten, On Sun, Aug 11, 2024 at 07:39:01PM GMT, Morten Welinder wrote: > The fmod man page recommends this code to get the least positive residue: > > z = fmod(x, y); > if (z < 0) > z += y; > > That last line should be "z += fabs (y);" Otherwise, for x=-0.25 and > y=-1 you get z=-1.25 which isn't what anyone is looking for. Thanks! I've applied the following patch: commit 5cf880bcb8f9a6678d37cad0ac2e17637e314f3f (HEAD -> contrib) Author: Alejandro Colomar <alx@xxxxxxxxxx> Date: Fri Aug 16 13:54:47 2024 +0200 fmod.3: Fix example Reported-by: Morten Welinder <mwelinder@xxxxxxxxx> Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx> diff --git a/man/man3/fmod.3 b/man/man3/fmod.3 index f5d80b2ce..20f0899d1 100644 --- a/man/man3/fmod.3 +++ b/man/man3/fmod.3 @@ -66,7 +66,7 @@ .SH DESCRIPTION .nf z = fmod(x, y); if (z < 0) - z += y; + z += fabs(y); .fi .in .P > The man page could perhaps also state that the sign of y has no effect > on the output, other than possibly when the result is a NaN. I'm not sure. That's already implied by saying that the return value is `x - trunc(x / y) * y`. We'd need to be careful with the wording to stay correct with NaN, so I think it's better to keep it as implicitly- stated information. Have a lovely day! Alex > > M. -- <https://www.alejandro-colomar.es/>
Attachment:
signature.asc
Description: PGP signature