e_remainderf.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* e_remainderf.c -- float version of e_remainder.c.
  2. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  3. */
  4. /*
  5. * ====================================================
  6. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7. *
  8. * Developed at SunPro, a Sun Microsystems, Inc. business.
  9. * Permission to use, copy, modify, and distribute this
  10. * software is freely granted, provided that this notice
  11. * is preserved.
  12. * ====================================================
  13. */
  14. #include "cdefs-compat.h"
  15. //__FBSDID("$FreeBSD: src/lib/msun/src/e_remainderf.c,v 1.8 2008/02/12 17:11:36 bde Exp $");
  16. #include "openlibm.h"
  17. #include "math_private.h"
  18. static const float zero = 0.0;
  19. DLLEXPORT float
  20. __ieee754_remainderf(float x, float p)
  21. {
  22. int32_t hx,hp;
  23. u_int32_t sx;
  24. float p_half;
  25. GET_FLOAT_WORD(hx,x);
  26. GET_FLOAT_WORD(hp,p);
  27. sx = hx&0x80000000;
  28. hp &= 0x7fffffff;
  29. hx &= 0x7fffffff;
  30. /* purge off exception values */
  31. if(hp==0) return (x*p)/(x*p); /* p = 0 */
  32. if((hx>=0x7f800000)|| /* x not finite */
  33. ((hp>0x7f800000))) /* p is NaN */
  34. return ((long double)x*p)/((long double)x*p);
  35. if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p); /* now x < 2p */
  36. if ((hx-hp)==0) return zero*x;
  37. x = fabsf(x);
  38. p = fabsf(p);
  39. if (hp<0x01000000) {
  40. if(x+x>p) {
  41. x-=p;
  42. if(x+x>=p) x -= p;
  43. }
  44. } else {
  45. p_half = (float)0.5*p;
  46. if(x>p_half) {
  47. x-=p;
  48. if(x>=p_half) x -= p;
  49. }
  50. }
  51. GET_FLOAT_WORD(hx,x);
  52. if ((hx&0x7fffffff)==0) hx = 0;
  53. SET_FLOAT_WORD(x,hx^sx);
  54. return x;
  55. }