root/lib/math/s_scalbnf.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. scalbnf

   1 /* s_scalbnf.c -- float version of s_scalbn.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 #include "stdlib.h"
  18 
  19 static const float
  20 two25   =  3.355443200e+07,        /* 0x4c000000 */
  21 twom25  =  2.9802322388e-08,        /* 0x33000000 */
  22 huge   = 1.0e+30,
  23 tiny   = 1.0e-30;
  24 
  25 float scalbnf (float x, int n)
  26 {
  27         int k,ix;
  28         GET_FLOAT_WORD(ix,x);
  29         k = (ix&0x7f800000)>>23;                /* extract exponent */
  30         if (k==0) {                                /* 0 or subnormal x */
  31             if ((ix&0x7fffffff)==0) return x; /* +-0 */
  32             x *= two25;
  33             GET_FLOAT_WORD(ix,x);
  34             k = ((ix&0x7f800000)>>23) - 25;
  35             if (n< -50000) return tiny*x;         /*underflow*/
  36         }
  37         if (k==0xff) return x+x;                /* NaN or Inf */
  38         k = k+n;
  39         if (k >  0xfe) return huge*copysignf(huge,x); /* overflow  */
  40         if (k > 0)                                 /* normal result */
  41             {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
  42         if (k <= -25) {
  43             if (n > 50000)         /* in case integer overflow in n+k */
  44                 return huge*copysignf(huge,x);        /*overflow*/
  45             else return tiny*copysignf(tiny,x);        /*underflow*/
  46         }
  47         k += 25;                                /* subnormal result */
  48         SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
  49         return x*twom25;
  50 }

/* [<][>][^][v][top][bottom][index][help] */