Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* ef_remainder.c -- float version of e_remainder.c.
  2.  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  3.  */
  4.  
  5. /*
  6.  * ====================================================
  7.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  8.  *
  9.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software is freely granted, provided that this notice
  12.  * is preserved.
  13.  * ====================================================
  14.  */
  15.  
  16. #include "fdlibm.h"
  17.  
  18. #ifdef __STDC__
  19. static const float zero = 0.0;
  20. #else
  21. static float zero = 0.0;
  22. #endif
  23.  
  24.  
  25. #ifdef __STDC__
  26.         float __ieee754_remainderf(float x, float p)
  27. #else
  28.         float __ieee754_remainderf(x,p)
  29.         float x,p;
  30. #endif
  31. {
  32.         __int32_t hx,hp;
  33.         __uint32_t sx;
  34.         float p_half;
  35.  
  36.         GET_FLOAT_WORD(hx,x);
  37.         GET_FLOAT_WORD(hp,p);
  38.         sx = hx&0x80000000;
  39.         hp &= 0x7fffffff;
  40.         hx &= 0x7fffffff;
  41.  
  42.     /* purge off exception values */
  43.         if(FLT_UWORD_IS_ZERO(hp)||
  44.            !FLT_UWORD_IS_FINITE(hx)||
  45.            FLT_UWORD_IS_NAN(hp))
  46.             return (x*p)/(x*p);
  47.  
  48.  
  49.         if (hp<=FLT_UWORD_HALF_MAX) x = __ieee754_fmodf(x,p+p); /* now x < 2p */
  50.         if ((hx-hp)==0) return zero*x;
  51.         x  = fabsf(x);
  52.         p  = fabsf(p);
  53.         if (hp<0x01000000) {
  54.             if(x+x>p) {
  55.                 x-=p;
  56.                 if(x+x>=p) x -= p;
  57.             }
  58.         } else {
  59.             p_half = (float)0.5*p;
  60.             if(x>p_half) {
  61.                 x-=p;
  62.                 if(x>=p_half) x -= p;
  63.             }
  64.         }
  65.         GET_FLOAT_WORD(hx,x);
  66.         SET_FLOAT_WORD(x,hx^sx);
  67.         return x;
  68. }
  69.