### 7.2.05

## remainder()

the standard C math library has a function;

this result is chosen to be between -y/2 and y/2. it's usual to choose remainders either between 0 and y, or between -y/2 and y/2. however, in the second case it is also usual to specify which of the 2 is chosen, if x = (n + 1/2)y.

the function returns the remainder on dividing x by y.

SYNOPSIS

#include <math.h>

double remainder(double x, double y);

this result is chosen to be between -y/2 and y/2. it's usual to choose remainders either between 0 and y, or between -y/2 and y/2. however, in the second case it is also usual to specify which of the 2 is chosen, if x = (n + 1/2)y.

the last sentence means that both -y/2 and y/2 are possible remainders, and both are used. this means that this function, for a given y, returns different values for x's which are a multiple of y apart, or in other words,

DESCRIPTION

The remainder() function returns the floating point

remainder r = x - ny when y is non-zero. The value n is the

integral value nearest the exact value x/y.When |n - x/y| =

1/2, the value n is chosen to be even.

*returns different values for numbers which have the same remainder on division by y.*```
```

#include <stdio.h>

#include <math.h>

int main()

{

printf("%d\n", (int)remainder(13,26));

printf("%d\n", (int)remainder(39,26));

return 0;

}

this is a pain.

9 % cc remainder.c -lm -o remainder

10 % remainder

13

-13