]>
Commit | Line | Data |
---|---|---|
7ce331c0 EA |
1 | /* |
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 | |
c4e44e97 | 7 | * software is freely granted, provided that this notice |
7ce331c0 EA |
8 | * is preserved. |
9 | * ==================================================== | |
10 | */ | |
11 | ||
7ce331c0 EA |
12 | /* |
13 | * __ieee754_scalb(x, fn) is provide for | |
c4e44e97 | 14 | * passing various standard test suite. One |
7ce331c0 EA |
15 | * should use scalbn() instead. |
16 | */ | |
17 | ||
18 | #include "math.h" | |
19 | #include "math_private.h" | |
30bd4a6c | 20 | #include <errno.h> |
7ce331c0 EA |
21 | |
22 | #ifdef _SCALB_INT | |
38b7304e | 23 | double attribute_hidden __ieee754_scalb(double x, int fn) |
7ce331c0 | 24 | #else |
38b7304e | 25 | double attribute_hidden __ieee754_scalb(double x, double fn) |
7ce331c0 EA |
26 | #endif |
27 | { | |
28 | #ifdef _SCALB_INT | |
29 | return scalbn(x,fn); | |
30bd4a6c | 30 | //TODO: just alias it to scalbn? |
7ce331c0 EA |
31 | #else |
32 | if (isnan(x)||isnan(fn)) return x*fn; | |
a0ebeb98 | 33 | if (!isfinite(fn)) { |
7ce331c0 EA |
34 | if(fn>0.0) return x*fn; |
35 | else return x/(-fn); | |
36 | } | |
37 | if (rint(fn)!=fn) return (fn-fn)/(fn-fn); | |
38 | if ( fn > 65000.0) return scalbn(x, 65000); | |
39 | if (-fn > 65000.0) return scalbn(x,-65000); | |
40 | return scalbn(x,(int)fn); | |
41 | #endif | |
42 | } | |
30bd4a6c DV |
43 | |
44 | /* | |
45 | * wrapper scalb(double x, double fn) is provide for | |
46 | * passing various standard test suite. One | |
47 | * should use scalbn() instead. | |
48 | */ | |
49 | #ifndef _IEEE_LIBM | |
50 | # ifdef _SCALB_INT | |
51 | double scalb(double x, int fn) | |
52 | # else | |
53 | double scalb(double x, double fn) | |
54 | # endif | |
55 | { | |
56 | double z = __ieee754_scalb(x, fn); | |
57 | if (_LIB_VERSION == _IEEE_) | |
58 | return z; | |
59 | if (!(isfinite(z) || isnan(z)) && isfinite(x)) | |
60 | return __kernel_standard(x, (double)fn, 32); /* scalb overflow */ | |
61 | if (z == 0.0 && z != x) | |
62 | return __kernel_standard(x, (double)fn, 33); /* scalb underflow */ | |
63 | # ifndef _SCALB_INT | |
64 | if (!isfinite(fn)) | |
65 | errno = ERANGE; | |
66 | # endif | |
67 | return z; | |
68 | } | |
69 | #else | |
70 | strong_alias(__ieee754_scalb, scalb) | |
71 | #endif |