For given floating point numbers x
and a
, I would like to compute r
(and n
) such that x = a*n + r
. In C/C++ this function is called fmod
. However I do not see a convenient function in .NET. Math.DivRem is only for integers ...
Formula of fmod:fmod= numerator - t*denominator.
Description. The fmod() function calculates the floating-point remainder of x/y. The absolute value of the result is always less than the absolute value of y. The result will have the same sign as x.
C library function - fmod() The C library function double fmod(double x, double y) returns the remainder of x divided by y.
Definition and Usage. The math. fmod() method returns the remainder (modulo) of x/y.
I think you can just use %
for floats as well. r = x % a
"Arithmetic operators (C# reference)":
All numeric types have predefined modulus operators.
I think you are looking for System.Math.IeeeRemainder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With