sqrtl.c revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * CDDL HEADER START
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * The contents of this file are subject to the terms of the
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * Common Development and Distribution License (the "License").
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * You may not use this file except in compliance with the License.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * See the License for the specific language governing permissions
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * and limitations under the License.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * When distributing Covered Code, include this CDDL HEADER in each
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * If applicable, add the following below this CDDL HEADER, with the
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * fields enclosed by brackets "[]" replaced with your own identifying
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * information: Portions Copyright [yyyy] [name of copyright owner]
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * CDDL HEADER END
bb25c06cca41ca78e5fb87fbb8e81d55beb18c95jg * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * Use is subject to license terms.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmextern int __swapTE(int);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmextern int __swapEX(int);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmextern enum fp_direction_type __swapRD(enum fp_direction_type);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * in struct longdouble, msw consists of
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * unsigned short sgn:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * unsigned short exp:15;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm * unsigned short frac1:16;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/* array indices used to access words within a double */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/* structure used to access words within a quad */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int frac4;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int frac3;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int frac2;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int msw;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm long double d;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/* default NaN returned for sqrt(neg) */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmstatic const union longdouble
bb25c06cca41ca78e5fb87fbb8e81d55beb18c95jg qnan = { 0xffffffff, 0xffffffff, 0xffffffff, 0x7fffffff };
bb25c06cca41ca78e5fb87fbb8e81d55beb18c95jg/* signalling NaN used to raise invalid */
bb25c06cca41ca78e5fb87fbb8e81d55beb18c95jgstatic const union {
bb25c06cca41ca78e5fb87fbb8e81d55beb18c95jg unsigned u[2];
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowe/* array indices used to access words within a double */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/* structure used to access words within a quad */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int msw;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int frac2;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int frac3;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned int frac4;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm long double d;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/* default NaN returned for sqrt(neg) */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmstatic const union longdouble
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm qnan = { 0x7fffffff, 0xffffffff, 0xffffffff, 0xffffffff };
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/* signalling NaN used to raise invalid */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmstatic const union {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm unsigned u[2];
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm#endif /* __LITTLE_ENDIAN */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmstatic const double
int ex;
if (ex)
w[0] = x->l.frac2;
w[0] = x->l.frac2;
w[0] = x->l.frac3;
w[0] = x->l.frac4;
ex--;
u.l[LOWORD] = 0;
u.l[LOWORD] = 0;
u.l[LOWORD] = 0;
u.l[LOWORD] = 0;
u.l[LOWORD] = 0;
s[0] = z[0] - one;
u.d = two36 + (s[0] + t);
s[0] -= (u.d - two36);
u.d = two4 + (s[0] + t);
s[0] -= (u.d - two4);
u.d = twom28 + (s[0] + t);
s[0] -= (u.d - twom28);
s[0] -= (u.d - twom60);
if (t != zero)
if (++frac4 == 0)
if (++frac3 == 0)
if (++frac2 == 0)
msw = 0;
exp++;
__q_tp_sqrt(const double *x, double *s)
tt[0] = t[0] + t[0];
if (c < zero)
union longdouble x;
t = zero;
t -= zero;
x.d = ldx;
return ldx;
t += snan.d;
t = -one;
t = sqrt(t);
return qnan.d;
t = -one;
t = sqrt(t);
return qnan.d;
ex--;
x.l.msw = 0;
inexact = 0;
if (inexact)
t = huge;
t += tiny;