Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. /* s_modff.c -- float version of s_modf.c.
  3.  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  4.  */
  5.  
  6. /*
  7.  * ====================================================
  8.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  9.  *
  10.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  11.  * Permission to use, copy, modify, and distribute this
  12.  * software is freely granted, provided that this notice
  13.  * is preserved.
  14.  * ====================================================
  15.  */
  16.  
  17. #if defined(LIBM_SCCS) && !defined(lint)
  18. static char rcsid[] = "$Id: s_modff.c,v 1.2 1994/08/18 23:07:12 jtc Exp $";
  19. #endif
  20.  
  21. #include "math.h"
  22. #include "math_private.h"
  23.  
  24. #ifdef __STDC__
  25. static const float one = 1.0;
  26. #else
  27. static float one = 1.0;
  28. #endif
  29.  
  30. #ifdef __STDC__
  31.         float modff(float x, float *iptr)
  32. #else
  33.         float modff(x, iptr)
  34.         float x,*iptr;
  35. #endif
  36. {
  37.         int32_t i0,j0;
  38.         u_int32_t i;
  39.         GET_FLOAT_WORD(i0,x);
  40.         j0 = ((i0>>23)&0xff)-0x7f;      /* exponent of x */
  41.         if(j0<23) {                     /* integer part in x */
  42.             if(j0<0) {                  /* |x|<1 */
  43.                 SET_FLOAT_WORD(*iptr,i0&0x80000000);    /* *iptr = +-0 */
  44.                 return x;
  45.             } else {
  46.                 i = (0x007fffff)>>j0;
  47.                 if((i0&i)==0) {                 /* x is integral */
  48.                     u_int32_t ix;
  49.                     *iptr = x;
  50.                     GET_FLOAT_WORD(ix,x);
  51.                     SET_FLOAT_WORD(x,ix&0x80000000);    /* return +-0 */
  52.                     return x;
  53.                 } else {
  54.                     SET_FLOAT_WORD(*iptr,i0&(~i));
  55.                     return x - *iptr;
  56.                 }
  57.             }
  58.         } else {                        /* no fraction part */
  59.             u_int32_t ix;
  60.             *iptr = x*one;
  61.             GET_FLOAT_WORD(ix,x);
  62.             SET_FLOAT_WORD(x,ix&0x80000000);    /* return +-0 */
  63.             return x;
  64.         }
  65. }
  66.