blob: 3fd78a1c0f9444da221f2d6e0c4537ba526a52e8 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
12/*
13 * __ieee754_scalb(x, fn) is provided for
14 * passing various standard test suites.
15 * One should use scalbn() instead.
16 */
17
18#include "math.h"
19#include "math_private.h"
20#include <errno.h>
21
22double attribute_hidden __ieee754_scalb(double x, double fn)
23{
24 if (isnan(x)||isnan(fn)) return x*fn;
25 if (!isfinite(fn)) {
26 if(fn>0.0) return x*fn;
27 else return x/(-fn);
28 }
29 if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
30 if ( fn > 65000.0) return scalbn(x, 65000);
31 if (-fn > 65000.0) return scalbn(x,-65000);
32 return scalbn(x,(int)fn);
33}
34
35#if defined __UCLIBC_SUSV3_LEGACY__
36/*
37 * wrapper scalb(double x, double fn) is provided for
38 * passing various standard test suites.
39 * One should use scalbn() instead.
40 */
41#ifndef _IEEE_LIBM
42double scalb(double x, double fn)
43{
44 double z = __ieee754_scalb(x, fn);
45 if (_LIB_VERSION == _IEEE_)
46 return z;
47 if (!(isfinite(z) || isnan(z)) && isfinite(x))
48 return __kernel_standard(x, (double)fn, 32); /* scalb overflow */
49 if (z == 0.0 && z != x)
50 return __kernel_standard(x, (double)fn, 33); /* scalb underflow */
51 if (!isfinite(fn))
52 errno = ERANGE;
53 return z;
54}
55#else
56strong_alias(__ieee754_scalb, scalb)
57#endif
58
59#endif /* UCLIBC_SUSV3_LEGACY */