2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / lang / w_sqrt.c
blob23a793ce74a694cb3abf0a4426480f9be7937afc
2 /* @(#)w_sqrt.c 5.1 93/09/24 */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
15 FUNCTION
16 <<sqrt>>, <<sqrtf>>---positive square root
18 INDEX
19 sqrt
20 INDEX
21 sqrtf
23 ANSI_SYNOPSIS
24 #include <math.h>
25 double sqrt(double <[x]>);
26 float sqrtf(float <[x]>);
28 TRAD_SYNOPSIS
29 #include <math.h>
30 double sqrt(<[x]>);
31 float sqrtf(<[x]>);
33 DESCRIPTION
34 <<sqrt>> computes the positive square root of the argument.
35 You can modify error handling for this function with
36 <<matherr>>.
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).
44 PORTABILITY
45 <<sqrt>> is ANSI C. <<sqrtf>> is an extension.
48 /*
49 * wrapper sqrt(x)
52 #include "fdlibm.h"
53 #include <errno.h>
55 #ifndef _DOUBLE_IS_32BITS
57 #ifdef __STDC__
58 double sqrt(double x) /* wrapper sqrt */
59 #else
60 double sqrt(x) /* wrapper sqrt */
61 double x;
62 #endif
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;
85 if (exc.err != 0)
86 errno = exc.err;
87 return exc.retval;
88 } else
89 return z;
90 #endif
93 #endif /* defined(_DOUBLE_IS_32BITS) */