1 
2 /* @(#)e_scalb.c 5.1 93/09/24 */
3 /*
4  * ====================================================
5  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6  *
7  * Developed at SunPro, a Sun Microsystems, Inc. business.
8  * Permission to use, copy, modify, and distribute this
9  * software is freely granted, provided that this notice
10  * is preserved.
11  * ====================================================
12  */
13 
14 /*
15  * scalb(x, fn) is provide for
16  * passing various standard test suite. One
17  * should use scalbn() instead.
18  */
19 
20 #include "fdlibm.h"
21 
22 #ifdef _NEED_FLOAT64
23 
24 __float64
scalb64(__float64 x,__float64 fn)25 scalb64(__float64 x, __float64 fn)
26 {
27     if (isnan(fn) || isnan(x))
28         return x + fn;
29 
30     if (isinf(fn)) {
31         if ((x == 0.0 && fn > 0.0) || (isinf(x) && fn < 0.0))
32             return __math_invalid(fn);
33         if (fn > 0.0)
34             return fn*x;
35         else
36             return x/(-fn);
37     }
38 
39     if (rint64(fn) != fn)
40         return __math_invalid(fn);
41 
42     if (fn > 4 * _FLOAT64_MAX_EXP)
43         fn = 4 * _FLOAT64_MAX_EXP;
44 
45     if (fn < -4 * _FLOAT64_MAX_EXP)
46         fn = -4 * _FLOAT64_MAX_EXP;
47 
48     return scalbn64(x, (int)fn);
49 }
50 
51 _MATH_ALIAS_d_dd(scalb)
52 
53 #endif /* _NEED_FLOAT64 */
54