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 ANSI_SYNOPSIS 24 #include <math.h> 25 double sqrt(double <[x]>); 26 float sqrtf(float <[x]>); 27 28 TRAD_SYNOPSIS 29 #include <math.h> 30 double sqrt(<[x]>); 31 float sqrtf(<[x]>); 32 33 DESCRIPTION 34 <<sqrt>> computes the positive square root of the argument. 35 You can modify error handling for this function with 36 <<matherr>>. 37 38 RETURNS 39 On success, the square root is returned. If <[x]> is real and 40 positive, then the result is positive. If <[x]> is real and 41 negative, the global value <<errno>> is set to <<EDOM>> (domain error). 42 43 44 PORTABILITY 45 <<sqrt>> is ANSI C. <<sqrtf>> is an extension. 46 */ 47 48 /* 49 * wrapper sqrt(x) 50 */ 51 52 #include "fdlibm.h" 53 #include <errno.h> 54 55 #ifndef _DOUBLE_IS_32BITS 56 57 #ifdef __STDC__ sqrt(double x)58 double sqrt(double x) /* wrapper sqrt */ 59 #else 60 double sqrt(x) /* wrapper sqrt */ 61 double x; 62 #endif 63 { 64 #ifdef _IEEE_LIBM 65 return __ieee754_sqrt(x); 66 #else 67 struct exception exc; 68 double z; 69 z = __ieee754_sqrt(x); 70 if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; 71 if(x<0.0) { 72 exc.type = DOMAIN; 73 exc.name = "sqrt"; 74 exc.err = 0; 75 exc.arg1 = exc.arg2 = x; 76 if (_LIB_VERSION == _SVID_) 77 exc.retval = 0.0; 78 else 79 exc.retval = 0.0/0.0; 80 if (_LIB_VERSION == _POSIX_) 81 errno = EDOM; 82 else if (!matherr(&exc)) { 83 errno = EDOM; 84 } 85 if (exc.err != 0) 86 errno = exc.err; 87 return exc.retval; 88 } else 89 return z; 90 #endif 91 } 92 93 #endif /* defined(_DOUBLE_IS_32BITS) */ 94