printf("the value of remainder is %f\n",remainder(x, y));
printf("the value of remainder is %f\n",x-(round(x/y)*y));
the value of remainder is 1.000000
the value of remainder is -1.000000
Floating point remainder. This is not like a normal modulo operation,
it can be negative for two positive numbers. It returns the exact
value of x–(round(x/y)·y).
There is a slight difference in what
remainder does. From the man page:
The remainder() function computes the remainder of dividing x by y. The return value is x-n*y, where n is the value x / y, rounded to the nearest integer. If the absolute value of x-n*y is 0.5, n is chosen to be even.
So in the halfway case the rounding part performed by
remainder does not round away from zero, but instead rounds to the nearest even number.