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 <math.h> |
17 | #include <math_private.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 |
26 | __scalblnf (float x, long int n) |
27 | { |
28 | int32_t k,ix; |
29 | GET_FLOAT_WORD(ix,x); |
30 | k = (ix&0x7f800000)>>23; /* extract exponent */ |
31 | if (__builtin_expect(k==0, 0)) { /* 0 or subnormal x */ |
32 | if ((ix&0x7fffffff)==0) return x; /* +-0 */ |
33 | x *= two25; |
34 | GET_FLOAT_WORD(ix,x); |
35 | k = ((ix&0x7f800000)>>23) - 25; |
36 | } |
37 | if (__builtin_expect(k==0xff, 0)) return x+x; /* NaN or Inf */ |
38 | if (__builtin_expect(n< -50000, 0)) |
39 | return tiny*copysignf(tiny,x); /*underflow*/ |
40 | if (__builtin_expect(n> 50000 || k+n > 0xfe, 0)) |
41 | return huge*copysignf(huge,x); /* overflow */ |
42 | /* Now k and n are bounded we know that k = k+n does not |
43 | overflow. */ |
44 | k = k+n; |
45 | if (__builtin_expect(k > 0, 1)) /* normal result */ |
46 | {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;} |
47 | if (k <= -25) |
48 | return tiny*copysignf(tiny,x); /*underflow*/ |
49 | k += 25; /* subnormal result */ |
50 | SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); |
51 | return x*twom25; |
52 | } |
53 | |