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 remquo(double x,double y,int * quo)10double remquo(double x, double 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 double div = x/y; 19 double integral; 20 double frac = modf(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 = round(div); 34 return x - *quo * y; 35 } 36