12fe8fb19SBen Gras /* @(#)w_sqrt.c 5.1 93/09/24 */
22fe8fb19SBen Gras /*
32fe8fb19SBen Gras * ====================================================
42fe8fb19SBen Gras * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
52fe8fb19SBen Gras *
62fe8fb19SBen Gras * Developed at SunPro, a Sun Microsystems, Inc. business.
72fe8fb19SBen Gras * Permission to use, copy, modify, and distribute this
82fe8fb19SBen Gras * software is freely granted, provided that this notice
92fe8fb19SBen Gras * is preserved.
102fe8fb19SBen Gras * ====================================================
112fe8fb19SBen Gras */
122fe8fb19SBen Gras
132fe8fb19SBen Gras #include <sys/cdefs.h>
142fe8fb19SBen Gras #if defined(LIBM_SCCS) && !defined(lint)
15*84d9c625SLionel Sambuc __RCSID("$NetBSD: w_sqrt.c,v 1.10 2013/11/19 19:24:34 joerg Exp $");
162fe8fb19SBen Gras #endif
172fe8fb19SBen Gras
182fe8fb19SBen Gras /*
192fe8fb19SBen Gras * wrapper sqrt(x)
202fe8fb19SBen Gras */
212fe8fb19SBen Gras
22*84d9c625SLionel Sambuc #include "namespace.h"
232fe8fb19SBen Gras #include "math.h"
242fe8fb19SBen Gras #include "math_private.h"
252fe8fb19SBen Gras
26*84d9c625SLionel Sambuc #ifndef __HAVE_LONG_DOUBLE
__strong_alias(_sqrtl,sqrt)27*84d9c625SLionel Sambuc __strong_alias(_sqrtl, sqrt)
28*84d9c625SLionel Sambuc __weak_alias(sqrtl, _sqrtl)
29*84d9c625SLionel Sambuc #endif
30*84d9c625SLionel Sambuc
312fe8fb19SBen Gras double
322fe8fb19SBen Gras sqrt(double x) /* wrapper sqrt */
332fe8fb19SBen Gras {
342fe8fb19SBen Gras #ifdef _IEEE_LIBM
352fe8fb19SBen Gras return __ieee754_sqrt(x);
362fe8fb19SBen Gras #else
372fe8fb19SBen Gras double z;
382fe8fb19SBen Gras z = __ieee754_sqrt(x);
392fe8fb19SBen Gras if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
402fe8fb19SBen Gras if(x<0.0) {
412fe8fb19SBen Gras return __kernel_standard(x,x,26); /* sqrt(negative) */
422fe8fb19SBen Gras } else
432fe8fb19SBen Gras return z;
442fe8fb19SBen Gras #endif
452fe8fb19SBen Gras }
46