-
Notifications
You must be signed in to change notification settings - Fork 25
/
e_scalb.c
103 lines (90 loc) · 2.26 KB
/
e_scalb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* @(#)e_scalb.c 1.3 95/01/18 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#include "fdlibm.h"
double __ieee754_scalb(double x, double fn)
{
long ifn;
if (isnan(x))
return x * fn;
if (!isfinite(fn))
{
if (isnan(fn) || fn > 0.0)
return x * fn;
if (x == 0.0)
return x;
return x / -fn;
}
ifn = (long) fn;
if ((double) ifn != fn)
{
if (__ieee754_rint(fn) != fn)
{
feraiseexcept(FE_INVALID);
return __builtin_nan("");
}
if (ifn > 65000l)
return __ieee754_scalbln(x, 65000l);
return __ieee754_scalbln(x, -65000l);
}
return __ieee754_scalbln(x, ifn);
}
static double __attribute__ ((noinline)) sysv_scalb(double x, double fn)
{
double z = __ieee754_scalb(x, fn);
if (isinf(z))
{
if (isfinite(x))
return __kernel_standard(x, fn, z, KMATHERR_SCALB_OVERFLOW); /* scalb overflow */
else
__set_errno(ERANGE);
} else if (z == 0.0 && z != x)
return __kernel_standard(x, fn, z, KMATHERR_SCALB_UNDERFLOW); /* scalb underflow */
return z;
}
/*
* wrapper scalb(double x, double fn) is provide for
* passing various standard test suite. One
* should use scalbn() instead.
*/
double __scalb(double x, double fn)
{
if (_LIB_VERSION == _SVID_)
{
return sysv_scalb(x, fn);
} else
{
double z = __ieee754_scalb(x, fn);
if (!isfinite(z) || z == 0.0)
{
if (isnan(z))
{
if (!isnan(x) && !isnan(fn))
z = __kernel_standard(x, fn, z, KMATHERR_SCALB_INVALID);
} else if (isinf(z))
{
if (!isinf(x) && !isinf(fn))
z = __kernel_standard(x, fn, z, KMATHERR_SCALB_OVERFLOW);
} else
{
/* z == 0. */
if (x != 0.0 && !isinf(fn))
z = __kernel_standard(x, fn, z, KMATHERR_SCALB_UNDERFLOW);
}
}
return z;
}
}
__typeof(__scalb) scalb __attribute__((weak, alias("__scalb")));
#ifdef __NO_LONG_DOUBLE_MATH
long double __scalbl(long double x, long double fn) __attribute__((alias("__scalb")));
__typeof(__scalbl) scalbl __attribute__((weak, alias("__scalb")));
#endif