ICU-315 add portable IEEEremainder implementation

X-SVN-Rev: 1066
This commit is contained in:
Alan Liu 2000-04-05 16:53:37 +00:00
parent 03d8cd3182
commit 5142b7614c

View File

@ -405,8 +405,27 @@ uprv_IEEEremainder(double x, double p)
return x;
#else
/* {sfb} need to fix this*/
return uprv_fmod(x, p);
/* Portable implementation of IEEEremainder. This implementation
* should work on platforms that do not have IEEE bit layouts.
* Deficiencies of this implementation are that it does not
* attempt to handle NaN or infinite parameters and it returns the
* dividend if the divisor is zero. This is probably not an issue
* on non-IEEE platforms. - aliu
*/
if (p == 0.0) { // zero divisor
return x;
}
double a = x / p;
double aint = uprv_floor(a);
double afrac = a - aint;
if (afrac > 0.5) {
aint += 1.0;
} else if (!(afrac < 0.5)) { // avoid == comparison
if (uprv_modf(aint / 2.0, &a) > 0.0) {
aint += 1.0;
}
}
return x - (p * aint);
#endif
}