This source file includes following definitions.
- sgl_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 "sgl_float.h"
31
32
33
34
35
36
37 unsigned int
38 sgl_fsqrt(
39 sgl_floating_point *srcptr,
40 unsigned int *nullptr,
41 sgl_floating_point *dstptr,
42 unsigned int *status)
43 {
44 register unsigned int src, result;
45 register int src_exponent;
46 register unsigned int newbit, sum;
47 register boolean guardbit = FALSE, even_exponent;
48
49 src = *srcptr;
50
51
52
53 if ((src_exponent = Sgl_exponent(src)) == SGL_INFINITY_EXPONENT) {
54
55
56
57 if (Sgl_isone_signaling(src)) {
58
59 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
60
61 Set_invalidflag();
62 Sgl_set_quiet(src);
63 }
64
65
66
67
68 if (Sgl_iszero_sign(src) || Sgl_isnotzero_mantissa(src)) {
69 *dstptr = src;
70 return(NOEXCEPTION);
71 }
72 }
73
74
75
76
77 if (Sgl_iszero_exponentmantissa(src)) {
78 *dstptr = src;
79 return(NOEXCEPTION);
80 }
81
82
83
84
85 if (Sgl_isone_sign(src)) {
86
87 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
88
89 Set_invalidflag();
90 Sgl_makequietnan(src);
91 *dstptr = src;
92 return(NOEXCEPTION);
93 }
94
95
96
97
98 if (src_exponent > 0) {
99 even_exponent = Sgl_hidden(src);
100 Sgl_clear_signexponent_set_hidden(src);
101 }
102 else {
103
104 Sgl_clear_signexponent(src);
105 src_exponent++;
106 Sgl_normalize(src,src_exponent);
107 even_exponent = src_exponent & 1;
108 }
109 if (even_exponent) {
110
111
112 Sgl_leftshiftby1(src);
113 }
114
115
116
117
118
119
120 Sgl_setzero(result);
121 newbit = 1 << SGL_P;
122 while (newbit && Sgl_isnotzero(src)) {
123 Sgl_addition(result,newbit,sum);
124 if(sum <= Sgl_all(src)) {
125
126 Sgl_addition(result,(newbit<<1),result);
127 Sgl_subtract(src,sum,src);
128 }
129 Sgl_rightshiftby1(newbit);
130 Sgl_leftshiftby1(src);
131 }
132
133 if (even_exponent) {
134 Sgl_rightshiftby1(result);
135 }
136
137
138 if (Sgl_isnotzero(src)) {
139 if (!even_exponent && Sgl_islessthan(result,src))
140 Sgl_increment(result);
141 guardbit = Sgl_lowmantissa(result);
142 Sgl_rightshiftby1(result);
143
144
145 switch (Rounding_mode()) {
146 case ROUNDPLUS:
147 Sgl_increment(result);
148 break;
149 case ROUNDNEAREST:
150
151
152 if (guardbit) {
153 Sgl_increment(result);
154 }
155 break;
156 }
157
158 if (Sgl_isone_hiddenoverflow(result)) src_exponent+=2;
159
160 if (Is_inexacttrap_enabled()) {
161 Sgl_set_exponent(result,
162 ((src_exponent-SGL_BIAS)>>1)+SGL_BIAS);
163 *dstptr = result;
164 return(INEXACTEXCEPTION);
165 }
166 else Set_inexactflag();
167 }
168 else {
169 Sgl_rightshiftby1(result);
170 }
171 Sgl_set_exponent(result,((src_exponent-SGL_BIAS)>>1)+SGL_BIAS);
172 *dstptr = result;
173 return(NOEXCEPTION);
174 }