#include "SDL_internal.h"1/*2* ====================================================3* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.4*5* Developed at SunPro, a Sun Microsystems, Inc. business.6* Permission to use, copy, modify, and distribute this7* software is freely granted, provided that this notice8* is preserved.9* ====================================================10*/1112/*13* scalbln(double x, long n)14* scalbln(x,n) returns x * 2**n computed by exponent15* manipulation rather than by actually performing an16* exponentiation or a multiplication.17*/1819#include "math_libm.h"20#include "math_private.h"21#include <limits.h>2223#ifdef __WATCOMC__ /* Watcom defines huge=__huge */24#undef huge25#endif2627static const double28two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */29twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */30huge = 1.0e+300,31tiny = 1.0e-300;3233double scalbln(double x, long n)34{35int32_t k, hx, lx;3637EXTRACT_WORDS(hx, lx, x);38k = (hx & 0x7ff00000) >> 20; /* extract exponent */39if (k == 0) { /* 0 or subnormal x */40if ((lx | (hx & 0x7fffffff)) == 0)41return x; /* +-0 */42x *= two54;43GET_HIGH_WORD(hx, x);44k = ((hx & 0x7ff00000) >> 20) - 54;45}46if (k == 0x7ff)47return x + x; /* NaN or Inf */48k = (int32_t)(k + n);49if (k > 0x7fe)50return huge * copysign(huge, x); /* overflow */51if (n < -50000)52return tiny * copysign(tiny, x); /* underflow */53if (k > 0) { /* normal result */54SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));55return x;56}57if (k <= -54) {58if (n > 50000) /* in case integer overflow in n+k */59return huge * copysign(huge, x); /* overflow */60return tiny * copysign(tiny, x); /* underflow */61}62k += 54; /* subnormal result */63SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));64return x * twom54;65}66libm_hidden_def(scalbln)676869double scalbn(double x, int n)70{71return scalbln(x, n);72}73libm_hidden_def(scalbn)747576