You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am writing some unit tests on nannou for a university course . I found that fmod has some slight differences compared to the C/C++ implementation. These specific examples are from the cppreference page on fmod.
As you can see, tests 2 and 3 are different. I believe this is due to the usage of floor (lower integer) rather than truncate (integer towards zero). The man page for fmod includes the following description:
These functions compute the floating-point remainder of dividing x by
y. The return value is x - n * y, where n is the quotient of x / y, rounded toward zero to an integer.
So I believe using trunc() here is the correct move if we want to be close to the C implementation. Using trunc results in the expected results (see Rust Playground here)
If the project agrees, I'd like to submit a PR and unit tests for this change. Thanks!
The text was updated successfully, but these errors were encountered:
Hi @bcliden. Thanks for opening the issue and for clearly showing the expected behaviour.
This seems reasonable to me. Feel free to open up a PR with this change. @mitchmindtree do you remember what you were referencing when you ported this function originally?
Hello, I am writing some unit tests on nannou for a university course . I found that
fmod
has some slight differences compared to the C/C++ implementation. These specific examples are from the cppreference page on fmod.C/C++ (tested with gcc 14.2.1 on fedora)
nannou math::fmod
As you can see, tests 2 and 3 are different. I believe this is due to the usage of
floor
(lower integer) rather thantruncate
(integer towards zero). The man page for fmod includes the following description:So I believe using
trunc()
here is the correct move if we want to be close to the C implementation. Using trunc results in the expected results (see Rust Playground here)If the project agrees, I'd like to submit a PR and unit tests for this change. Thanks!
The text was updated successfully, but these errors were encountered: