This source file includes following definitions.
- dbl_fsqrt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include "float.h"
30 #include "dbl_float.h"
31
32
33
34
35
36
37 unsigned int
38 dbl_fsqrt(
39 dbl_floating_point *srcptr,
40 unsigned int *nullptr,
41 dbl_floating_point *dstptr,
42 unsigned int *status)
43 {
44 register unsigned int srcp1, srcp2, resultp1, resultp2;
45 register unsigned int newbitp1, newbitp2, sump1, sump2;
46 register int src_exponent;
47 register boolean guardbit = FALSE, even_exponent;
48
49 Dbl_copyfromptr(srcptr,srcp1,srcp2);
50
51
52
53 if ((src_exponent = Dbl_exponent(srcp1)) == DBL_INFINITY_EXPONENT) {
54
55
56
57 if (Dbl_isone_signaling(srcp1)) {
58
59 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
60
61 Set_invalidflag();
62 Dbl_set_quiet(srcp1);
63 }
64
65
66
67
68 if (Dbl_iszero_sign(srcp1) ||
69 Dbl_isnotzero_mantissa(srcp1,srcp2)) {
70 Dbl_copytoptr(srcp1,srcp2,dstptr);
71 return(NOEXCEPTION);
72 }
73 }
74
75
76
77
78 if (Dbl_iszero_exponentmantissa(srcp1,srcp2)) {
79 Dbl_copytoptr(srcp1,srcp2,dstptr);
80 return(NOEXCEPTION);
81 }
82
83
84
85
86 if (Dbl_isone_sign(srcp1)) {
87
88 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
89
90 Set_invalidflag();
91 Dbl_makequietnan(srcp1,srcp2);
92 Dbl_copytoptr(srcp1,srcp2,dstptr);
93 return(NOEXCEPTION);
94 }
95
96
97
98
99 if (src_exponent > 0) {
100 even_exponent = Dbl_hidden(srcp1);
101 Dbl_clear_signexponent_set_hidden(srcp1);
102 }
103 else {
104
105 Dbl_clear_signexponent(srcp1);
106 src_exponent++;
107 Dbl_normalize(srcp1,srcp2,src_exponent);
108 even_exponent = src_exponent & 1;
109 }
110 if (even_exponent) {
111
112
113 Dbl_leftshiftby1(srcp1,srcp2);
114 }
115
116
117
118
119
120
121 Dbl_setzero(resultp1,resultp2);
122 Dbl_allp1(newbitp1) = 1 << (DBL_P - 32);
123 Dbl_setzero_mantissap2(newbitp2);
124 while (Dbl_isnotzero(newbitp1,newbitp2) && Dbl_isnotzero(srcp1,srcp2)) {
125 Dbl_addition(resultp1,resultp2,newbitp1,newbitp2,sump1,sump2);
126 if(Dbl_isnotgreaterthan(sump1,sump2,srcp1,srcp2)) {
127 Dbl_leftshiftby1(newbitp1,newbitp2);
128
129 Dbl_addition(resultp1,resultp2,newbitp1,newbitp2,
130 resultp1,resultp2);
131 Dbl_subtract(srcp1,srcp2,sump1,sump2,srcp1,srcp2);
132 Dbl_rightshiftby2(newbitp1,newbitp2);
133 }
134 else {
135 Dbl_rightshiftby1(newbitp1,newbitp2);
136 }
137 Dbl_leftshiftby1(srcp1,srcp2);
138 }
139
140 if (even_exponent) {
141 Dbl_rightshiftby1(resultp1,resultp2);
142 }
143
144
145 if (Dbl_isnotzero(srcp1,srcp2)) {
146 if (!even_exponent && Dbl_islessthan(resultp1,resultp2,srcp1,srcp2)) {
147 Dbl_increment(resultp1,resultp2);
148 }
149 guardbit = Dbl_lowmantissap2(resultp2);
150 Dbl_rightshiftby1(resultp1,resultp2);
151
152
153 switch (Rounding_mode()) {
154 case ROUNDPLUS:
155 Dbl_increment(resultp1,resultp2);
156 break;
157 case ROUNDNEAREST:
158
159
160 if (guardbit) {
161 Dbl_increment(resultp1,resultp2);
162 }
163 break;
164 }
165
166 if (Dbl_isone_hiddenoverflow(resultp1)) src_exponent+=2;
167
168 if (Is_inexacttrap_enabled()) {
169 Dbl_set_exponent(resultp1,
170 ((src_exponent-DBL_BIAS)>>1)+DBL_BIAS);
171 Dbl_copytoptr(resultp1,resultp2,dstptr);
172 return(INEXACTEXCEPTION);
173 }
174 else Set_inexactflag();
175 }
176 else {
177 Dbl_rightshiftby1(resultp1,resultp2);
178 }
179 Dbl_set_exponent(resultp1,((src_exponent-DBL_BIAS)>>1)+DBL_BIAS);
180 Dbl_copytoptr(resultp1,resultp2,dstptr);
181 return(NOEXCEPTION);
182 }