src/libm/s_scalbn.c
changeset 3337 9ac6f0782dd6
parent 3162 dc1eb82ffdaa
child 6044 35448a5ea044
equal deleted inserted replaced
3336:00fab0ebfe54 3337:9ac6f0782dd6
    31 #else
    31 #else
    32      static double
    32      static double
    33 #endif
    33 #endif
    34        two54 = 1.80143985094819840000e+16,      /* 0x43500000, 0x00000000 */
    34        two54 = 1.80143985094819840000e+16,      /* 0x43500000, 0x00000000 */
    35          twom54 = 5.55111512312578270212e-17,   /* 0x3C900000, 0x00000000 */
    35          twom54 = 5.55111512312578270212e-17,   /* 0x3C900000, 0x00000000 */
    36          huge = 1.0e+300, tiny = 1.0e-300;
    36          huge_val = 1.0e+300, tiny = 1.0e-300;
    37 
    37 
    38 libm_hidden_proto(scalbn)
    38 libm_hidden_proto(scalbn)
    39 #ifdef __STDC__
    39 #ifdef __STDC__
    40      double scalbn(double x, int n)
    40      double scalbn(double x, int n)
    41 #else
    41 #else
    58     }
    58     }
    59     if (k == 0x7ff)
    59     if (k == 0x7ff)
    60         return x + x;           /* NaN or Inf */
    60         return x + x;           /* NaN or Inf */
    61     k = k + n;
    61     k = k + n;
    62     if (k > 0x7fe)
    62     if (k > 0x7fe)
    63         return huge * copysign(huge, x);        /* overflow  */
    63         return huge_val * copysign(huge_val, x);        /* overflow  */
    64     if (k > 0) {                /* normal result */
    64     if (k > 0) {                /* normal result */
    65         SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
    65         SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
    66         return x;
    66         return x;
    67     }
    67     }
    68     if (k <= -54) {
    68     if (k <= -54) {
    69         if (n > 50000)          /* in case integer overflow in n+k */
    69         if (n > 50000)          /* in case integer overflow in n+k */
    70             return huge * copysign(huge, x);    /*overflow */
    70             return huge_val * copysign(huge_val, x);    /*overflow */
    71         else
    71         else
    72             return tiny * copysign(tiny, x);    /*underflow */
    72             return tiny * copysign(tiny, x);    /*underflow */
    73     }
    73     }
    74     k += 54;                    /* subnormal result */
    74     k += 54;                    /* subnormal result */
    75     SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
    75     SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));