Rev 4872 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | |
2 | /* |
||
3 | * ==================================================== |
||
4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
||
5 | * |
||
6 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
||
7 | * Permission to use, copy, modify, and distribute this |
||
8 | * software is freely granted, provided that this notice |
||
9 | * is preserved. |
||
10 | * ==================================================== |
||
11 | */ |
||
12 | |||
13 | |||
14 | * wrapper scalb(double x, double fn) is provide for |
||
15 | * passing various standard test suite. One |
||
16 | * should use scalbn() instead. |
||
17 | */ |
||
18 | |||
19 | |||
20 | #include |
||
21 | |||
22 | |||
23 | |||
24 | |||
25 | #ifdef _SCALB_INT |
||
26 | double scalb(double x, int fn) /* wrapper scalb */ |
||
27 | #else |
||
28 | double scalb(double x, double fn) /* wrapper scalb */ |
||
29 | #endif |
||
30 | #else |
||
31 | double scalb(x,fn) /* wrapper scalb */ |
||
32 | #ifdef _SCALB_INT |
||
33 | double x; int fn; |
||
34 | #else |
||
35 | double x,fn; |
||
36 | #endif |
||
37 | #endif |
||
38 | { |
||
39 | #ifdef _IEEE_LIBM |
||
40 | return __ieee754_scalb(x,fn); |
||
41 | #else |
||
42 | double z; |
||
43 | #ifndef HUGE_VAL |
||
44 | #define HUGE_VAL inf |
||
45 | double inf = 0.0; |
||
46 | |||
47 | |||
48 | #endif |
||
49 | struct exception exc; |
||
50 | z = __ieee754_scalb(x,fn); |
||
51 | if(_LIB_VERSION == _IEEE_) return z; |
||
52 | if(!(finite(z)||isnan(z))&&finite(x)) { |
||
53 | /* scalb overflow; SVID also returns +-HUGE_VAL */ |
||
54 | exc.type = OVERFLOW; |
||
55 | exc.name = "scalb"; |
||
56 | exc.err = 0; |
||
57 | exc.arg1 = x; |
||
58 | exc.arg2 = fn; |
||
59 | exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL; |
||
60 | if (_LIB_VERSION == _POSIX_) |
||
61 | errno = ERANGE; |
||
62 | else if (!matherr(&exc)) { |
||
63 | errno = ERANGE; |
||
64 | } |
||
65 | if (exc.err != 0) |
||
66 | errno = exc.err; |
||
67 | return exc.retval; |
||
68 | } |
||
69 | if(z==0.0&&z!=x) { |
||
70 | /* scalb underflow */ |
||
71 | exc.type = UNDERFLOW; |
||
72 | exc.name = "scalb"; |
||
73 | exc.err = 0; |
||
74 | exc.arg1 = x; |
||
75 | exc.arg2 = fn; |
||
76 | exc.retval = copysign(0.0,x); |
||
77 | if (_LIB_VERSION == _POSIX_) |
||
78 | errno = ERANGE; |
||
79 | else if (!matherr(&exc)) { |
||
80 | errno = ERANGE; |
||
81 | } |
||
82 | if (exc.err != 0) |
||
83 | errno = exc.err; |
||
84 | return exc.retval; |
||
85 | } |
||
86 | #ifndef _SCALB_INT |
||
87 | if(!finite(fn)) errno = ERANGE; |
||
88 | #endif |
||
89 | return z; |
||
90 | #endif |
||
91 | } |
||
92 | |||
93 | |||
94 |