• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 
7 #include <math.h>
8 #include <errno.h>
9 
remquof(float x,float y,int * quo)10 float remquof(float x, float y, int *quo)
11 {
12   if (isnan(x))
13     return x;
14   if (isnan(y))
15     return y;
16   if (isinf(x) || y == 0)
17     return NAN;
18   float div = x/y;
19   float integral;
20   float frac = modff(div, &integral);
21   int iintegral = (int)integral;
22   if (frac == 0.5) {
23     if (iintegral & 1)
24       *quo = iintegral + 1;
25     else
26       *quo = iintegral;
27   } else if (frac == -0.5) {
28     if (iintegral & 1)
29       *quo = iintegral - 1;
30     else
31       *quo = iintegral;
32   } else
33     *quo = roundf(div);
34   return x - *quo * y;
35 }
36