Ticket #758: tryfloatval_mod.c

File tryfloatval_mod.c, 463 bytes (added by doughera, 13 years ago)
Line 
1#include <math.h>
2#include <stdio.h>
3
4double
5floatval_mod(double n2, double n3)
6{
7    return (n2 - n3 * floor(n2 / n3));
8}
9void
10try(double x, double y, double answer)
11{
12    printf("floor(%4.1f/%4.1f) = %4.1f, floatval_mod(%4.1f, %4.1f) = %4.1f,  expect %4.1f\n",
13        x, y, floor(x/y), x, y, floatval_mod(x, y), answer);
14    return;
15}
16
17int main(int argc, char **argv)
18{
19    try(5.0,  -3.0, -1.0);
20    try(-5.0,  3.0,  1.0);
21    try(-5.0, -3.0, -2.0);
22    return 0;
23}