xref: /freebsd/lib/msun/src/s_scalbnl.c (revision 1603881667360c015f6685131f2f25474fa67a72)
1 #include <math.h>
2 #include <float.h>
3 #include "math_private.h"
4 #include "fpmath.h"
5 /*
6  * scalbnl (long double x, int n)
7  * scalbnl(x,n) returns x* 2**n  computed by  exponent
8  * manipulation rather than by actually performing an
9  * exponentiation or a multiplication.
10  */
11 #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
12 long double scalbnl(long double x, int n)
13 {
14 	union IEEEl2bits u;
15 
16 	if (n > 16383) {
17 		x *= 0x1p16383L;
18 		n -= 16383;
19 		if (n > 16383) {
20 			x *= 0x1p16383L;
21 			n -= 16383;
22 			if (n > 16383)
23 				n = 16383;
24 		}
25 	} else if (n < -16382) {
26 		x *= 0x1p-16382L * 0x1p113L;
27 		n += 16382 - 113;
28 		if (n < -16382) {
29 			x *= 0x1p-16382L * 0x1p113L;
30 			n += 16382 - 113;
31 			if (n < -16382)
32 				n = -16382;
33 		}
34 	}
35 	u.e = 1.0;
36 	u.xbits.expsign = 0x3fff + n;
37 	return x * u.e;
38 }
39 __strong_reference(scalbnl, ldexpl);
40 #endif
41 
42