Subversion Repositories Kolibri OS

Rev

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

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. /* @(#)s_frexp.c 5.1 93/09/24 */
  3. /*
  4.  * ====================================================
  5.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6.  *
  7.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software is freely granted, provided that this notice
  10.  * is preserved.
  11.  * ====================================================
  12.  */
  13.  
  14. #if defined(LIBM_SCCS) && !defined(lint)
  15. static char rcsid[] = "$Id: s_frexp.c,v 1.6 1994/08/18 23:06:49 jtc Exp $";
  16. #endif
  17.  
  18. /*
  19.  * for non-zero x
  20.  *      x = frexp(arg,&exp);
  21.  * return a double fp quantity x such that 0.5 <= |x| <1.0
  22.  * and the corresponding binary exponent "exp". That is
  23.  *      arg = x*2^exp.
  24.  * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
  25.  * with *exp=0.
  26.  */
  27.  
  28. #include "math.h"
  29. #include "math_private.h"
  30.  
  31. #ifdef __STDC__
  32. static const double
  33. #else
  34. static double
  35. #endif
  36. one   =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
  37. two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
  38.  
  39. #ifdef __STDC__
  40.         double frexp(double x, int *eptr)
  41. #else
  42.         double frexp(x, eptr)
  43.         double x; int *eptr;
  44. #endif
  45. {
  46.         int32_t hx, ix, lx;
  47.         EXTRACT_WORDS(hx,lx,x);
  48.         ix = 0x7fffffff&hx;
  49.         *eptr = 0;
  50.         if(ix>=0x7ff00000||((ix|lx)==0)) return x;      /* 0,inf,nan */
  51.         if (ix<0x00100000) {            /* subnormal */
  52.             x *= two54;
  53.             GET_HIGH_WORD(hx,x);
  54.             ix = hx&0x7fffffff;
  55.             *eptr = -54;
  56.         }
  57.         *eptr += (ix>>20)-1022;
  58.         hx = (hx&0x800fffff)|0x3fe00000;
  59.         SET_HIGH_WORD(x,hx);
  60.         return x;
  61. }
  62.