Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3362 | 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 | FUNCTION |
||
15 | < |
||
16 | |||
17 | |||
18 | sqrt |
||
19 | INDEX |
||
20 | sqrtf |
||
21 | |||
22 | |||
23 | #include |
||
24 | double sqrt(double <[x]>); |
||
25 | float sqrtf(float <[x]>); |
||
26 | |||
27 | |||
28 | #include |
||
29 | double sqrt(<[x]>); |
||
30 | float sqrtf(<[x]>); |
||
31 | |||
32 | |||
33 | < |
||
34 | You can modify error handling for this function with |
||
35 | < |
||
36 | |||
37 | |||
38 | On success, the square root is returned. If <[x]> is real and |
||
39 | positive, then the result is positive. If <[x]> is real and |
||
40 | negative, the global value < |
||
41 | |||
42 | |||
43 | |||
44 | < |
||
45 | */ |
||
46 | |||
47 | |||
48 | * wrapper sqrt(x) |
||
49 | */ |
||
50 | |||
51 | |||
52 | #include |
||
53 | |||
54 | |||
55 | |||
56 | |||
57 | double sqrt(double x) /* wrapper sqrt */ |
||
58 | #else |
||
59 | double sqrt(x) /* wrapper sqrt */ |
||
60 | double x; |
||
61 | #endif |
||
62 | { |
||
63 | #ifdef _IEEE_LIBM |
||
64 | return __ieee754_sqrt(x); |
||
65 | #else |
||
66 | struct exception exc; |
||
67 | double z; |
||
68 | z = __ieee754_sqrt(x); |
||
69 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; |
||
70 | if(x<0.0) { |
||
71 | exc.type = DOMAIN; |
||
72 | exc.name = "sqrt"; |
||
73 | exc.err = 0; |
||
74 | exc.arg1 = exc.arg2 = x; |
||
75 | if (_LIB_VERSION == _SVID_) |
||
76 | exc.retval = 0.0; |
||
77 | else |
||
78 | exc.retval = 0.0/0.0; |
||
79 | if (_LIB_VERSION == _POSIX_) |
||
80 | errno = EDOM; |
||
81 | else if (!matherr(&exc)) { |
||
82 | errno = EDOM; |
||
83 | } |
||
84 | if (exc.err != 0) |
||
85 | errno = exc.err; |
||
86 | return exc.retval; |
||
87 | } else |
||
88 | return z; |
||
89 | #endif |
||
90 | } |
||
91 | |||
92 | |||
93 |