Atlas - s_scalbn.c

Home / ext / SDL / src / libm Lines: 1 | Size: 1863 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1#include "SDL_internal.h" 2/* 3 * ==================================================== 4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 * 6 * Developed at SunPro, a Sun Microsystems, Inc. business. 7 * Permission to use, copy, modify, and distribute this 8 * software is freely granted, provided that this notice 9 * is preserved. 10 * ==================================================== 11 */ 12 13/* 14 * scalbln(double x, long n) 15 * scalbln(x,n) returns x * 2**n computed by exponent 16 * manipulation rather than by actually performing an 17 * exponentiation or a multiplication. 18 */ 19 20#include "math_libm.h" 21#include "math_private.h" 22#include <limits.h> 23 24static const double 25two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ 26twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ 27huge = 1.0e+300, 28tiny = 1.0e-300; 29 30double scalbln(double x, long n) 31{ 32 int32_t k, hx, lx; 33 34 EXTRACT_WORDS(hx, lx, x); 35 k = (hx & 0x7ff00000) >> 20; /* extract exponent */ 36 if (k == 0) { /* 0 or subnormal x */ 37 if ((lx | (hx & 0x7fffffff)) == 0) 38 return x; /* +-0 */ 39 x *= two54; 40 GET_HIGH_WORD(hx, x); 41 k = ((hx & 0x7ff00000) >> 20) - 54; 42 } 43 if (k == 0x7ff) 44 return x + x; /* NaN or Inf */ 45 k = (int32_t)(k + n); 46 if (k > 0x7fe) 47 return huge * copysign(huge, x); /* overflow */ 48 if (n < -50000) 49 return tiny * copysign(tiny, x); /* underflow */ 50 if (k > 0) { /* normal result */ 51 SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20)); 52 return x; 53 } 54 if (k <= -54) { 55 if (n > 50000) /* in case integer overflow in n+k */ 56 return huge * copysign(huge, x); /* overflow */ 57 return tiny * copysign(tiny, x); /* underflow */ 58 } 59 k += 54; /* subnormal result */ 60 SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20)); 61 return x * twom54; 62} 63libm_hidden_def(scalbln) 64 65 66double scalbn(double x, int n) 67{ 68 return scalbln(x, n); 69} 70libm_hidden_def(scalbn) 71
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.