Subversion Repositories Kolibri OS

Rev

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

  1. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  3. #include <math.h>
  4.  
  5. double
  6. ldexp(double v, int e)
  7. {
  8.   double two = 2.0;
  9.  
  10.   if (e < 0)
  11.   {
  12.     e = -e; /* This just might overflow on two-complement machines.  */
  13.     if (e < 0) return 0.0;
  14.     while (e > 0)
  15.     {
  16.       if (e & 1) v /= two;
  17.       two *= two;
  18.       e >>= 1;
  19.     }
  20.   }
  21.   else if (e > 0)
  22.   {
  23.     while (e > 0)
  24.     {
  25.       if (e & 1) v *= two;
  26.       two *= two;
  27.       e >>= 1;
  28.     }
  29.   }
  30.   return v;
  31. }
  32.  
  33.