Lines Matching refs:C4
249 // add/subtract C4 and C3 * 10^scale; this may follow a previous rounding, so
260 UINT256 C4,
332 // for Cases (15), (16), (17) C4 > C3 * 10^scale because C4 has at least
335 // add/subtract C4 and C3 * 10^scale; the exponent is e4
336 if (p_sign == z_sign) { // R256 = C4 + R256
337 // calculate R256 = C4 + C3 * 10^scale = C4 + R256 which is exact,
339 add256 (C4, R256, &R256);
340 } else { // if (p_sign != z_sign) { // R256 = C4 - R256
341 // calculate R256 = C4 - C3 * 10^scale = C4 - R256 or
342 // R256 = C3 * 10^scale - C4 = R256 - C4 which is exact,
345 // compare first R256 = C3 * 10^scale and C4
346 if (R256.w[3] > C4.w[3] || (R256.w[3] == C4.w[3] && R256.w[2] > C4.w[2]) ||
347 (R256.w[3] == C4.w[3] && R256.w[2] == C4.w[2] && R256.w[1] > C4.w[1]) ||
348 (R256.w[3] == C4.w[3] && R256.w[2] == C4.w[2] && R256.w[1] == C4.w[1] &&
349 R256.w[0] >= C4.w[0])) { // C3 * 10^scale >= C4
350 // calculate R256 = C3 * 10^scale - C4 = R256 - C4, which is exact,
352 sub256 (R256, C4, &R256);
355 } else { // if C4 > C3 * 10^scale
356 // calculate R256 = C4 - C3 * 10^scale = C4 - R256, which is exact,
358 sub256 (C4, R256, &R256);
661 UINT256 C4;
1141 // calculate C4 = C1 * C2 and determine q
1142 C4.w[3] = C4.w[2] = C4.w[1] = C4.w[0] = 0;
1143 if (q1 + q2 <= 19) { // if 2 <= q1 + q2 <= 19, C4 = C1 * C2 fits in 64 bits
1144 C4.w[0] = C1.w[0] * C2.w[0];
1145 // if C4 < 10^(q1+q2-1) then q4 = q1 + q2 - 1 else q4 = q1 + q2
1146 if (C4.w[0] < ten2k64[q1 + q2 - 1])
1151 } else if (q1 + q2 == 20) { // C4 = C1 * C2 fits in 64 or 128 bits
1153 __mul_64x64_to_128MACH (C4, C1.w[0], C2.w[0]);
1154 // if C4 < 10^(q1+q2-1) = 10^19 then q4 = q1+q2-1 = 19 else q4 = q1+q2 = 20
1155 if (C4.w[1] == 0 && C4.w[0] < ten2k64[19]) { // 19 = q1+q2-1
1159 // if (C4.w[1] == 0)
1166 // C4 = C1 * C2 fits in 64 or 128 bits
1167 // (64 bits possibly, but only when q1 + q2 = 21 and C4 has 20 digits)
1170 __mul_128x64_to_128 (C4, C1.w[0], C2);
1172 __mul_128x64_to_128 (C4, C2.w[0], C1);
1174 // if C4 < 10^(q1+q2-1) then q4 = q1 + q2 - 1 else q4 = q1 + q2
1175 if (C4.w[1] < ten2k128[q1 + q2 - 21].w[1] ||
1176 (C4.w[1] == ten2k128[q1 + q2 - 21].w[1] &&
1177 C4.w[0] < ten2k128[q1 + q2 - 21].w[0])) {
1178 // if (C4.w[1] == 0) // q4 = 20, necessarily
1187 } else if (q1 + q2 == 39) { // C4 = C1 * C2 fits in 128 or 192 bits
1190 __mul_128x128_to_256 (C4, C1, C2); // C4.w[3] is 0
1191 // if C4 < 10^(q1+q2-1) = 10^38 then q4 = q1+q2-1 = 38 else q4 = q1+q2 = 39
1192 if (C4.w[2] == 0 && (C4.w[1] < ten2k128[18].w[1] ||
1193 (C4.w[1] == ten2k128[18].w[1]
1194 && C4.w[0] < ten2k128[18].w[0]))) {
1199 // if (C4.w[2] == 0)
1206 // C4 = C1 * C2 fits in 128 or 192 bits
1207 // (128 bits possibly, but only when q1 + q2 = 40 and C4 has 39 digits)
1212 __mul_64x128_full (C4.w[2], C4, C1.w[0], C2);
1215 __mul_64x128_full (C4.w[2], C4, C2.w[0], C1);
1217 // may use __mul_128x128_to_192 (C4.w[2], C4.w[0], C2.w[0], C1);
1218 __mul_128x128_to_256 (C4, C1, C2); // C4.w[3] = 0
1220 // if C4 < 10^(q1+q2-1) then q4 = q1 + q2 - 1 else q4 = q1 + q2
1221 if (C4.w[2] < ten2k256[q1 + q2 - 40].w[2] ||
1222 (C4.w[2] == ten2k256[q1 + q2 - 40].w[2] &&
1223 (C4.w[1] < ten2k256[q1 + q2 - 40].w[1] ||
1224 (C4.w[1] == ten2k256[q1 + q2 - 40].w[1] &&
1225 C4.w[0] < ten2k256[q1 + q2 - 40].w[0])))) {
1226 // if (C4.w[2] == 0) // q4 = 39, necessarily
1235 } else if (q1 + q2 == 58) { // C4 = C1 * C2 fits in 192 or 256 bits
1239 __mul_64x128_full (C4.w[2], C4, C1.w[0], C2); // may use 64x128_to_192
1241 __mul_64x128_full (C4.w[2], C4, C2.w[0], C1); // may use 64x128_to_192
1243 __mul_128x128_to_256 (C4, C1, C2);
1245 // if C4 < 10^(q1+q2-1) = 10^57 then q4 = q1+q2-1 = 57 else q4 = q1+q2 = 58
1246 if (C4.w[3] == 0 && (C4.w[2] < ten2k256[18].w[2] ||
1247 (C4.w[2] == ten2k256[18].w[2]
1248 && (C4.w[1] < ten2k256[18].w[1]
1249 || (C4.w[1] == ten2k256[18].w[1]
1250 && C4.w[0] < ten2k256[18].w[0]))))) {
1255 // if (C4.w[3] == 0)
1262 // C4 = C1 * C2 fits in 192 or 256 bits
1263 // (192 bits possibly, but only when q1 + q2 = 59 and C4 has 58 digits)
1266 // may use __mul_128x128_to_192 (C4.w[2], C4.w[0], C2.w[0], C1);
1267 __mul_128x128_to_256 (C4, C1, C2); // C4.w[3] = 0
1268 // if C4 < 10^(q1+q2-1) then q4 = q1 + q2 - 1 else q4 = q1 + q2
1269 if (C4.w[3] < ten2k256[q1 + q2 - 40].w[3] ||
1270 (C4.w[3] == ten2k256[q1 + q2 - 40].w[3] &&
1271 (C4.w[2] < ten2k256[q1 + q2 - 40].w[2] ||
1272 (C4.w[2] == ten2k256[q1 + q2 - 40].w[2] &&
1273 (C4.w[1] < ten2k256[q1 + q2 - 40].w[1] ||
1274 (C4.w[1] == ten2k256[q1 + q2 - 40].w[1] &&
1275 C4.w[0] < ten2k256[q1 + q2 - 40].w[0])))))) {
1276 // if (C4.w[3] == 0) // q4 = 58, necessarily
1293 // truncate C4 to p34 digits into res
1297 P128.w[1] = C4.w[1];
1298 P128.w[0] = C4.w[0];
1304 P192.w[2] = C4.w[2];
1305 P192.w[1] = C4.w[1];
1306 P192.w[0] = C4.w[0];
1314 round256_58_76 (q4, x0, C4, &R256, &incr_exp,
1329 // C4 * 10^e4 is the result rounded to the destination precision, with
1333 // e4 is too large, but can be brought within range by scaling up C4
1335 // res = (C4 * 10^scale) * 10^expmax
1336 if (q4 <= 19) { // C4 fits in 64 bits
1338 // 64 x 64 C4.w[0] * ten2k64[scale]
1339 __mul_64x64_to_128MACH (res, C4.w[0], ten2k64[scale]);
1341 // 64 x 128 C4.w[0] * ten2k128[scale - 20]
1342 __mul_128x64_to_128 (res, C4.w[0], ten2k128[scale - 20]);
1344 } else { // C4 fits in 128 bits, but 10^scale must fit in 64 bits
1346 __mul_128x64_to_128 (res, ten2k64[scale], C4);
1351 res.w[1] = C4.w[1];
1352 res.w[0] = C4.w[0];
1526 // return (C4 * 10^scale) * 10^(e4 - scale)
1534 } else if (q4 <= 19) { // C4 fits in 64 bits
1744 // there is a gap of exactly one digit between the scaled C3 and C4
1758 R64 = C4.w[0];
1760 // if q4 > 1 then truncate C4 from q4 digits to 1 digit;
1763 round64_2_18 (q4, q4 - 1, C4.w[0], &R64, &incr_exp,
1768 P128.w[1] = C4.w[1];
1769 P128.w[0] = C4.w[0];
1777 P192.w[2] = C4.w[2];
1778 P192.w[1] = C4.w[1];
1779 P192.w[0] = C4.w[0];
1787 round256_58_76 (q4, q4 - 1, C4, &R256, &incr_exp,
1798 if (q4 == 1 && C4.w[0] == 5) {
1930 if (C4.w[0] < midpoint64[q4 - 1]) { // < 1/2 ulp
1932 } else if (C4.w[0] == midpoint64[q4 - 1]) { // = 1/2 ulp
1938 if (C4.w[2] == 0 && (C4.w[1] < midpoint128[q4 - 20].w[1] ||
1939 (C4.w[1] == midpoint128[q4 - 20].w[1] &&
1940 C4.w[0] < midpoint128[q4 - 20].w[0]))) { // < 1/2 ulp
1942 } else if (C4.w[2] == 0 && C4.w[1] == midpoint128[q4 - 20].w[1] &&
1943 C4.w[0] == midpoint128[q4 - 20].w[0]) { // = 1/2 ulp
1949 if (C4.w[3] == 0 && (C4.w[2] < midpoint192[q4 - 39].w[2] ||
1950 (C4.w[2] == midpoint192[q4 - 39].w[2] &&
1951 C4.w[1] < midpoint192[q4 - 39].w[1]) ||
1952 (C4.w[2] == midpoint192[q4 - 39].w[2] &&
1953 C4.w[1] == midpoint192[q4 - 39].w[1] &&
1954 C4.w[0] < midpoint192[q4 - 39].w[0]))) { // < 1/2 ulp
1956 } else if (C4.w[3] == 0 && C4.w[2] == midpoint192[q4 - 39].w[2] &&
1957 C4.w[1] == midpoint192[q4 - 39].w[1] &&
1958 C4.w[0] == midpoint192[q4 - 39].w[0]) { // = 1/2 ulp
1964 if (C4.w[3] < midpoint256[q4 - 59].w[3] ||
1965 (C4.w[3] == midpoint256[q4 - 59].w[3] &&
1966 C4.w[2] < midpoint256[q4 - 59].w[2]) ||
1967 (C4.w[3] == midpoint256[q4 - 59].w[3] &&
1968 C4.w[2] == midpoint256[q4 - 59].w[2] &&
1969 C4.w[1] < midpoint256[q4 - 59].w[1]) ||
1970 (C4.w[3] == midpoint256[q4 - 59].w[3] &&
1971 C4.w[2] == midpoint256[q4 - 59].w[2] &&
1972 C4.w[1] == midpoint256[q4 - 59].w[1] &&
1973 C4.w[0] < midpoint256[q4 - 59].w[0])) { // < 1/2 ulp
1975 } else if (C4.w[3] == midpoint256[q4 - 59].w[3] &&
1976 C4.w[2] == midpoint256[q4 - 59].w[2] &&
1977 C4.w[1] == midpoint256[q4 - 59].w[1] &&
1978 C4.w[0] == midpoint256[q4 - 59].w[0]) { // = 1/2 ulp
2100 // the result is exact if exp > expmin and C4 = d*10^(q4-1),
2104 // result coefficient = 10^34 - C4
2106 res.w[0] = 0x378d8e6400000000ull - C4.w[0];
2111 // if q4 > 1 then truncate C4 from q4 digits to 1 digit;
2114 round64_2_18 (q4, q4 - 1, C4.w[0], &R64, &incr_exp,
2120 P128.w[1] = C4.w[1];
2121 P128.w[0] = C4.w[0];
2129 P192.w[2] = C4.w[2];
2130 P192.w[1] = C4.w[1];
2131 P192.w[0] = C4.w[0];
2139 round256_58_76 (q4, q4 - 1, C4, &R256, &incr_exp,
2156 // We want R64 to be the top digit of C4, but we actually
2157 // obtained (C4 * 10^(-q4+1))RN; a correction may be needed,
2158 // because the top digit is (C4 * 10^(-q4+1))RZ
2163 // the result is inexact as C4 has more than 1 significant digit
2170 // C4 - R64 * 10^(q4-1) with 1/2 ulp
2175 // calculate C4 - R64 * 10^(q4-1); this is a rare case and
2232 // tininess is C4 > 050...0 [q4 digits] which is met because
2233 // the msd of C4 is not zero)
2301 // by scaling up C4 by 10^(q3 - delta - q4)
2303 if (q4 <= 19) { // 1 <= scale <= 19; C4 fits in 64 bits
2305 // 64 x 64 C4.w[0] * ten2k64[scale]
2306 __mul_64x64_to_128MACH (P128, C4.w[0], ten2k64[scale]);
2308 // 64 x 128 C4.w[0] * ten2k128[scale - 20]
2309 __mul_128x64_to_128 (P128, C4.w[0], ten2k128[scale - 20]);
2311 } else { // C4 fits in 128 bits, but 10^scale must fit in 64 bits
2312 // 64 x 128 ten2k64[scale] * C4
2313 __mul_128x64_to_128 (P128, ten2k64[scale], C4);
2315 C4.w[0] = P128.w[0];
2316 C4.w[1] = P128.w[1];
2358 // round C4 to nearest to q4 - x0 digits, where x0 = delta + q4 - p34,
2366 R128.w[1] = C4.w[1];
2367 R128.w[0] = C4.w[0];
2370 round64_2_18 (q4, x0, C4.w[0], &R64, &incr_exp,
2381 P128.w[1] = C4.w[1];
2382 P128.w[0] = C4.w[0];
2399 P192.w[2] = C4.w[2];
2400 P192.w[1] = C4.w[1];
2401 P192.w[0] = C4.w[0];
2423 round256_58_76 (q4, x0, C4, &R256, &incr_exp,
2445 // now add C3 * 10^scale in res and the signed top (q4-x0) digits of C4,
2584 lsb = res.w[0] & 0x01; // lsb of C3 * 10^scale; R128 contains rounded C4
2613 // because the result has opposite sign to that of C4 which was
2866 // cancellation can occur, so it is better to scale either C3 or C4 and
2875 // (17) if we swap (C3, C4), (q3, q4), (e3, e4), (z_sign, p_sign)
2877 // C4.w[3] = 0 and C4.w[2] = 0, so swap just the low part of C4 with C3
2880 C3.w[1] = C4.w[1];
2881 C3.w[0] = C4.w[0];
2882 C4.w[1] = P128.w[1];
2883 C4.w[0] = P128.w[0];
2899 add_and_round (q3, q4, e4, delta, p34, z_sign, p_sign, C3, C4,
2918 // truncate C4 to p34 digits into res
2922 P128.w[1] = C4.w[1];
2923 P128.w[0] = C4.w[0];
2929 P192.w[2] = C4.w[2];
2930 P192.w[1] = C4.w[1];
2931 P192.w[0] = C4.w[0];
2939 round256_58_76 (q4, x0, C4, &R256, &incr_exp,
2952 // if C4 rounded to p34 digits is exact then the result is inexact,
3072 // Case (8) is similar to Case (1), with C3 and C4 swapped
3073 // Case (9) is similar to Case (2), with C3 and C4 swapped
3074 // Case (10) is similar to Case (3), with C3 and C4 swapped
3075 // Case (13) is similar to Case (4), with C3 and C4 swapped
3076 // Case (14) is similar to Case (5), with C3 and C4 swapped
3077 // Case (18) is similar to Case (6), with C3 and C4 swapped
3079 // swap (C3, C4), (q3, q4), (e3, 34), (z_sign, p_sign), (z_exp, p_exp)
3081 // C4.w[3] = 0 and C4.w[2] = 0, so swap just the low part of C4 with C3
3084 C3.w[1] = C4.w[1];
3085 C3.w[0] = C4.w[0];
3086 C4.w[1] = P128.w[1];
3087 C4.w[0] = P128.w[0];
3132 // now add/subtract the 256-bit C4 and the new (and shorter) 128-bit C3;
3138 if (p_sign == z_sign) { // R256 = C4 + R256
3139 add256 (C4, R256, &R256);
3140 } else { // if (p_sign != z_sign) { // R256 = C4 - R256
3141 sub256 (C4, R256, &R256); // the result cannot be pure zero
3144 lsb = C4.w[0] & 0x01;
3545 add_and_round (q3, q4, e4, delta, p34, z_sign, p_sign, C3, C4,