blob: d78fe245a0120679c6b970bd7e4cd9eb7daa6b89 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* 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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080016#include <sys/cdefs.h>
Elliott Hughes8da8ca42018-05-08 13:35:33 -070017__FBSDID("$FreeBSD: head/lib/msun/src/s_scalbnf.c 306409 2016-09-28 14:48:34Z emaste $");
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080018
19#include "math.h"
20#include "math_private.h"
21
22static const float
23two25 = 3.355443200e+07, /* 0x4c000000 */
24twom25 = 2.9802322388e-08, /* 0x33000000 */
25huge = 1.0e+30,
26tiny = 1.0e-30;
27
28float
29scalbnf (float x, int n)
30{
31 int32_t k,ix;
32 GET_FLOAT_WORD(ix,x);
33 k = (ix&0x7f800000)>>23; /* extract exponent */
34 if (k==0) { /* 0 or subnormal x */
35 if ((ix&0x7fffffff)==0) return x; /* +-0 */
36 x *= two25;
37 GET_FLOAT_WORD(ix,x);
38 k = ((ix&0x7f800000)>>23) - 25;
39 if (n< -50000) return tiny*x; /*underflow*/
40 }
41 if (k==0xff) return x+x; /* NaN or Inf */
42 k = k+n;
43 if (k > 0xfe) return huge*copysignf(huge,x); /* overflow */
44 if (k > 0) /* normal result */
45 {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
Elliott Hughes8da8ca42018-05-08 13:35:33 -070046 if (k <= -25) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047 if (n > 50000) /* in case integer overflow in n+k */
48 return huge*copysignf(huge,x); /*overflow*/
Elliott Hughes8da8ca42018-05-08 13:35:33 -070049 else
50 return tiny*copysignf(tiny,x); /*underflow*/
51 }
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052 k += 25; /* subnormal result */
53 SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
54 return x*twom25;
55}
56
57__strong_reference(scalbnf, ldexpf);