[444] | 1 | |
---|
| 2 | /* @(#)w_sqrt.c 5.1 93/09/24 */ |
---|
| 3 | /* |
---|
| 4 | * ==================================================== |
---|
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
| 6 | * |
---|
| 7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
| 8 | * Permission to use, copy, modify, and distribute this |
---|
| 9 | * software is freely granted, provided that this notice |
---|
| 10 | * is preserved. |
---|
| 11 | * ==================================================== |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | FUNCTION |
---|
| 16 | <<sqrt>>, <<sqrtf>>---positive square root |
---|
| 17 | |
---|
| 18 | INDEX |
---|
| 19 | sqrt |
---|
| 20 | INDEX |
---|
| 21 | sqrtf |
---|
| 22 | |
---|
| 23 | SYNOPSIS |
---|
| 24 | #include <math.h> |
---|
| 25 | double sqrt(double <[x]>); |
---|
| 26 | float sqrtf(float <[x]>); |
---|
| 27 | |
---|
| 28 | DESCRIPTION |
---|
| 29 | <<sqrt>> computes the positive square root of the argument. |
---|
| 30 | You can modify error handling for this function with |
---|
| 31 | <<matherr>>. |
---|
| 32 | |
---|
| 33 | RETURNS |
---|
| 34 | On success, the square root is returned. If <[x]> is real and |
---|
| 35 | positive, then the result is positive. If <[x]> is real and |
---|
| 36 | negative, the global value <<errno>> is set to <<EDOM>> (domain error). |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | PORTABILITY |
---|
| 40 | <<sqrt>> is ANSI C. <<sqrtf>> is an extension. |
---|
| 41 | */ |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * wrapper sqrt(x) |
---|
| 45 | */ |
---|
| 46 | |
---|
| 47 | #include "fdlibm.h" |
---|
| 48 | #include <errno.h> |
---|
| 49 | |
---|
| 50 | #ifndef _DOUBLE_IS_32BITS |
---|
| 51 | |
---|
| 52 | #ifdef __STDC__ |
---|
| 53 | double sqrt(double x) /* wrapper sqrt */ |
---|
| 54 | #else |
---|
| 55 | double sqrt(x) /* wrapper sqrt */ |
---|
| 56 | double x; |
---|
| 57 | #endif |
---|
| 58 | { |
---|
| 59 | #ifdef _IEEE_LIBM |
---|
| 60 | return __ieee754_sqrt(x); |
---|
| 61 | #else |
---|
| 62 | struct exception exc; |
---|
| 63 | double z; |
---|
| 64 | z = __ieee754_sqrt(x); |
---|
| 65 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; |
---|
| 66 | if(x<0.0) { |
---|
| 67 | exc.type = DOMAIN; |
---|
| 68 | exc.name = "sqrt"; |
---|
| 69 | exc.err = 0; |
---|
| 70 | exc.arg1 = exc.arg2 = x; |
---|
| 71 | if (_LIB_VERSION == _SVID_) |
---|
| 72 | exc.retval = 0.0; |
---|
| 73 | else |
---|
| 74 | exc.retval = 0.0/0.0; |
---|
| 75 | if (_LIB_VERSION == _POSIX_) |
---|
| 76 | errno = EDOM; |
---|
| 77 | else if (!matherr(&exc)) { |
---|
| 78 | errno = EDOM; |
---|
| 79 | } |
---|
| 80 | if (exc.err != 0) |
---|
| 81 | errno = exc.err; |
---|
| 82 | return exc.retval; |
---|
| 83 | } else |
---|
| 84 | return z; |
---|
| 85 | #endif |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|