1 /* Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "bid_internal.h"
31 static const UINT64 mult_factor[16] = {
32 1ull, 10ull, 100ull, 1000ull,
33 10000ull, 100000ull, 1000000ull, 10000000ull,
34 100000000ull, 1000000000ull, 10000000000ull, 100000000000ull,
35 1000000000000ull, 10000000000000ull,
36 100000000000000ull, 1000000000000000ull
39 #if DECIMAL_CALL_BY_REFERENCE
41 __bid64_quiet_equal (int *pres, UINT64 * px,
43 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
49 __bid64_quiet_equal (UINT64 x,
50 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
54 int exp_x, exp_y, exp_t;
55 UINT64 sig_x, sig_y, sig_t;
56 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y, lcv;
59 // if either number is NAN, the comparison is unordered,
60 // rather than equal : return 0
61 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
62 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
63 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
69 // if all the bits are the same, these numbers are equivalent.
75 if (((x & MASK_INF) == MASK_INF) && ((y & MASK_INF) == MASK_INF)) {
76 res = (((x ^ y) & MASK_SIGN) != MASK_SIGN);
79 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
80 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
81 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
82 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
83 if (sig_x > 9999999999999999ull) {
89 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
90 sig_x = (x & MASK_BINARY_SIG1);
93 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
94 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
95 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
96 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
97 if (sig_y > 9999999999999999ull) {
103 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
104 sig_y = (y & MASK_BINARY_SIG1);
109 // (+ZERO==-ZERO) => therefore ignore the sign
110 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
111 // therefore ignore the exponent field
112 // (Any non-canonical # is considered 0)
113 if (non_canon_x || sig_x == 0) {
116 if (non_canon_y || sig_y == 0) {
119 if (x_is_zero && y_is_zero) {
122 } else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
126 // OPPOSITE SIGN (CASE5)
127 // now, if the sign bits differ => not equal : return 0
128 if ((x ^ y) & MASK_SIGN) {
132 // REDUNDANT REPRESENTATIONS (CASE6)
133 if (exp_x > exp_y) { // to simplify the loop below,
134 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
135 SWAP (sig_x, sig_y, sig_t); // and the smaller exp in x
137 if (exp_y - exp_x > 15) {
138 res = 0; // difference cannot be greater than 10^15
141 for (lcv = 0; lcv < (exp_y - exp_x); lcv++) {
142 // recalculate y's significand upwards
144 if (sig_y > 9999999999999999ull) {
149 res = (sig_y == sig_x);
153 #if DECIMAL_CALL_BY_REFERENCE
155 __bid64_quiet_greater (int *pres, UINT64 * px,
157 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
163 __bid64_quiet_greater (UINT64 x,
164 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
171 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
174 // if either number is NAN, the comparison is unordered, rather than equal :
176 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
177 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
178 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
184 // if all the bits are the same, these numbers are equal (not Greater).
190 if ((x & MASK_INF) == MASK_INF) {
191 // if x is neg infinity, there is no way it is greater than y, return 0
192 if (((x & MASK_SIGN) == MASK_SIGN)) {
196 // x is pos infinity, it is greater, unless y is positive
197 // infinity => return y!=pos_infinity
198 res = (((y & MASK_INF) != MASK_INF)
199 || ((y & MASK_SIGN) == MASK_SIGN));
202 } else if ((y & MASK_INF) == MASK_INF) {
203 // x is finite, so if y is positive infinity, then x is less, return 0
204 // if y is negative infinity, then x is greater, return 1
205 res = ((y & MASK_SIGN) == MASK_SIGN);
208 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
209 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
210 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
211 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
212 if (sig_x > 9999999999999999ull) {
218 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
219 sig_x = (x & MASK_BINARY_SIG1);
222 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
223 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
224 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
225 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
226 if (sig_y > 9999999999999999ull) {
232 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
233 sig_y = (y & MASK_BINARY_SIG1);
238 //(+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
239 //(ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore ignore the
241 // (Any non-canonical # is considered 0)
242 if (non_canon_x || sig_x == 0) {
245 if (non_canon_y || sig_y == 0) {
248 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
249 if (x_is_zero && y_is_zero) {
252 } else if (x_is_zero) {
253 // is x is zero, it is greater if Y is negative
254 res = ((y & MASK_SIGN) == MASK_SIGN);
256 } else if (y_is_zero) {
257 // is y is zero, X is greater if it is positive
258 res = ((x & MASK_SIGN) != MASK_SIGN);
261 // OPPOSITE SIGN (CASE5)
262 // now, if the sign bits differ, x is greater if y is negative
263 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
264 res = ((y & MASK_SIGN) == MASK_SIGN);
267 // REDUNDANT REPRESENTATIONS (CASE6)
268 // if both components are either bigger or smaller,
269 // it is clear what needs to be done
270 if (sig_x > sig_y && exp_x > exp_y) {
271 res = ((x & MASK_SIGN) != MASK_SIGN);
274 if (sig_x < sig_y && exp_x < exp_y) {
275 res = ((x & MASK_SIGN) == MASK_SIGN);
278 // if exp_x is 15 greater than exp_y, no need for compensation
279 if (exp_x - exp_y > 15) { // difference cannot be greater than 10^15
280 if (x & MASK_SIGN) // if both are negative
282 else // if both are positive
286 // if exp_x is 15 less than exp_y, no need for compensation
287 if (exp_y - exp_x > 15) {
288 if (x & MASK_SIGN) // if both are negative
290 else // if both are positive
294 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
295 if (exp_x > exp_y) { // to simplify the loop below,
296 // otherwise adjust the x significand upwards
297 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
298 mult_factor[exp_x - exp_y]);
299 // if postitive, return whichever significand is larger (converse if neg.)
300 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
304 res = (((sig_n_prime.w[1] > 0)
305 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
309 // adjust the y significand upwards
310 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
311 mult_factor[exp_y - exp_x]);
312 // if postitive, return whichever significand is larger
313 // (converse if negative)
314 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
318 res = (((sig_n_prime.w[1] == 0)
319 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
324 #if DECIMAL_CALL_BY_REFERENCE
326 __bid64_quiet_greater_equal (int *pres, UINT64 * px,
328 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
334 __bid64_quiet_greater_equal (UINT64 x,
335 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
342 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
345 // if either number is NAN, the comparison is unordered : return 1
346 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
347 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
348 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
354 // if all the bits are the same, these numbers are equal.
360 if ((x & MASK_INF) == MASK_INF) {
361 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
362 if ((x & MASK_SIGN) == MASK_SIGN) {
363 // x is -inf, so it is less than y unless y is -inf
364 res = (((y & MASK_INF) == MASK_INF)
365 && (y & MASK_SIGN) == MASK_SIGN);
367 } else { // x is pos_inf, no way for it to be less than y
371 } else if ((y & MASK_INF) == MASK_INF) {
375 res = ((y & MASK_SIGN) == MASK_SIGN);
378 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
379 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
380 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
381 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
382 if (sig_x > 9999999999999999ull) {
388 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
389 sig_x = (x & MASK_BINARY_SIG1);
392 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
393 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
394 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
395 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
396 if (sig_y > 9999999999999999ull) {
402 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
403 sig_y = (y & MASK_BINARY_SIG1);
408 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
409 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
410 // therefore ignore the exponent field
411 // (Any non-canonical # is considered 0)
412 if (non_canon_x || sig_x == 0) {
415 if (non_canon_y || sig_y == 0) {
418 if (x_is_zero && y_is_zero) {
419 // if both numbers are zero, they are equal
422 } else if (x_is_zero) {
423 // if x is zero, it is lessthan if Y is positive
424 res = ((y & MASK_SIGN) == MASK_SIGN);
426 } else if (y_is_zero) {
427 // if y is zero, X is less if it is negative
428 res = ((x & MASK_SIGN) != MASK_SIGN);
431 // OPPOSITE SIGN (CASE5)
432 // now, if the sign bits differ, x is less than if y is positive
433 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
434 res = ((y & MASK_SIGN) == MASK_SIGN);
437 // REDUNDANT REPRESENTATIONS (CASE6)
438 // if both components are either bigger or smaller
439 if (sig_x > sig_y && exp_x >= exp_y) {
440 res = ((x & MASK_SIGN) != MASK_SIGN);
443 if (sig_x < sig_y && exp_x <= exp_y) {
444 res = ((x & MASK_SIGN) == MASK_SIGN);
447 // if exp_x is 15 greater than exp_y, no need for compensation
448 if (exp_x - exp_y > 15) {
449 res = ((x & MASK_SIGN) != MASK_SIGN);
450 // difference cannot be greater than 10^15
453 // if exp_x is 15 less than exp_y, no need for compensation
454 if (exp_y - exp_x > 15) {
455 res = ((x & MASK_SIGN) == MASK_SIGN);
458 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
459 if (exp_x > exp_y) { // to simplify the loop below,
460 // otherwise adjust the x significand upwards
461 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
462 mult_factor[exp_x - exp_y]);
463 // return 1 if values are equal
464 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
468 // if postitive, return whichever significand abs is smaller
469 // (converse if negative)
470 res = (((sig_n_prime.w[1] == 0)
471 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
475 // adjust the y significand upwards
476 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
477 mult_factor[exp_y - exp_x]);
478 // return 0 if values are equal
479 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
483 // if positive, return whichever significand abs is smaller
484 // (converse if negative)
485 res = (((sig_n_prime.w[1] > 0)
486 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
491 #if DECIMAL_CALL_BY_REFERENCE
493 __bid64_quiet_greater_unordered (int *pres, UINT64 * px,
495 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
501 __bid64_quiet_greater_unordered (UINT64 x,
502 UINT64 y _EXC_FLAGS_PARAM
503 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
509 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
512 // if either number is NAN, the comparison is unordered, rather than equal :
514 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
515 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
516 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
522 // if all the bits are the same, these numbers are equal (not Greater).
528 if ((x & MASK_INF) == MASK_INF) {
529 // if x is neg infinity, there is no way it is greater than y, return 0
530 if (((x & MASK_SIGN) == MASK_SIGN)) {
534 // x is pos infinity, it is greater, unless y is positive infinity =>
535 // return y!=pos_infinity
536 res = (((y & MASK_INF) != MASK_INF)
537 || ((y & MASK_SIGN) == MASK_SIGN));
540 } else if ((y & MASK_INF) == MASK_INF) {
541 // x is finite, so if y is positive infinity, then x is less, return 0
542 // if y is negative infinity, then x is greater, return 1
543 res = ((y & MASK_SIGN) == MASK_SIGN);
546 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
547 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
548 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
549 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
550 if (sig_x > 9999999999999999ull) {
556 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
557 sig_x = (x & MASK_BINARY_SIG1);
560 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
561 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
562 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
563 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
564 if (sig_y > 9999999999999999ull) {
570 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
571 sig_y = (y & MASK_BINARY_SIG1);
576 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
577 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
578 // therefore ignore the exponent field
579 // (Any non-canonical # is considered 0)
580 if (non_canon_x || sig_x == 0) {
583 if (non_canon_y || sig_y == 0) {
586 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
587 if (x_is_zero && y_is_zero) {
590 } else if (x_is_zero) {
591 // is x is zero, it is greater if Y is negative
592 res = ((y & MASK_SIGN) == MASK_SIGN);
594 } else if (y_is_zero) {
595 // is y is zero, X is greater if it is positive
596 res = ((x & MASK_SIGN) != MASK_SIGN);
599 // OPPOSITE SIGN (CASE5)
600 // now, if the sign bits differ, x is greater if y is negative
601 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
602 res = ((y & MASK_SIGN) == MASK_SIGN);
605 // REDUNDANT REPRESENTATIONS (CASE6)
606 // if both components are either bigger or smaller
607 if (sig_x > sig_y && exp_x >= exp_y) {
608 res = ((x & MASK_SIGN) != MASK_SIGN);
611 if (sig_x < sig_y && exp_x <= exp_y) {
612 res = ((x & MASK_SIGN) == MASK_SIGN);
615 // if exp_x is 15 greater than exp_y, no need for compensation
616 if (exp_x - exp_y > 15) {
617 // difference cannot be greater than 10^15
618 res = ((x & MASK_SIGN) != MASK_SIGN);
621 // if exp_x is 15 less than exp_y, no need for compensation
622 if (exp_y - exp_x > 15) {
623 res = ((x & MASK_SIGN) == MASK_SIGN);
626 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
627 if (exp_x > exp_y) { // to simplify the loop below,
628 // otherwise adjust the x significand upwards
629 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
630 mult_factor[exp_x - exp_y]);
631 // if postitive, return whichever significand is larger
632 // (converse if negative)
633 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
637 res = (((sig_n_prime.w[1] > 0)
638 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
642 // adjust the y significand upwards
643 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
644 mult_factor[exp_y - exp_x]);
645 // if postitive, return whichever significand is larger (converse if negative)
646 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
650 res = (((sig_n_prime.w[1] == 0)
651 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
656 #if DECIMAL_CALL_BY_REFERENCE
658 __bid64_quiet_less (int *pres, UINT64 * px,
660 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM)
666 __bid64_quiet_less (UINT64 x,
667 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
674 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
677 // if either number is NAN, the comparison is unordered : return 0
678 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
679 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
680 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
686 // if all the bits are the same, these numbers are equal.
692 if ((x & MASK_INF) == MASK_INF) {
693 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
694 if ((x & MASK_SIGN) == MASK_SIGN) {
695 // x is -inf, so it is less than y unless y is -inf
696 res = (((y & MASK_INF) != MASK_INF)
697 || (y & MASK_SIGN) != MASK_SIGN);
700 // x is pos_inf, no way for it to be less than y
704 } else if ((y & MASK_INF) == MASK_INF) {
708 res = ((y & MASK_SIGN) != MASK_SIGN);
711 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
712 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
713 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
714 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
715 if (sig_x > 9999999999999999ull) {
721 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
722 sig_x = (x & MASK_BINARY_SIG1);
725 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
726 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
727 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
728 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
729 if (sig_y > 9999999999999999ull) {
735 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
736 sig_y = (y & MASK_BINARY_SIG1);
741 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
742 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
743 // therefore ignore the exponent field
744 // (Any non-canonical # is considered 0)
745 if (non_canon_x || sig_x == 0) {
748 if (non_canon_y || sig_y == 0) {
751 if (x_is_zero && y_is_zero) {
752 // if both numbers are zero, they are equal
755 } else if (x_is_zero) {
756 // if x is zero, it is lessthan if Y is positive
757 res = ((y & MASK_SIGN) != MASK_SIGN);
759 } else if (y_is_zero) {
760 // if y is zero, X is less if it is negative
761 res = ((x & MASK_SIGN) == MASK_SIGN);
764 // OPPOSITE SIGN (CASE5)
765 // now, if the sign bits differ, x is less than if y is positive
766 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
767 res = ((y & MASK_SIGN) != MASK_SIGN);
770 // REDUNDANT REPRESENTATIONS (CASE6)
771 // if both components are either bigger or smaller,
772 // it is clear what needs to be done
773 if (sig_x > sig_y && exp_x >= exp_y) {
774 res = ((x & MASK_SIGN) == MASK_SIGN);
777 if (sig_x < sig_y && exp_x <= exp_y) {
778 res = ((x & MASK_SIGN) != MASK_SIGN);
781 // if exp_x is 15 greater than exp_y, no need for compensation
782 if (exp_x - exp_y > 15) {
783 res = ((x & MASK_SIGN) == MASK_SIGN);
784 // difference cannot be greater than 10^15
787 // if exp_x is 15 less than exp_y, no need for compensation
788 if (exp_y - exp_x > 15) {
789 res = ((x & MASK_SIGN) != MASK_SIGN);
792 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
793 if (exp_x > exp_y) { // to simplify the loop below,
794 // otherwise adjust the x significand upwards
795 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
796 mult_factor[exp_x - exp_y]);
797 // return 0 if values are equal
798 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
802 // if postitive, return whichever significand abs is smaller
803 // (converse if negative)
804 res = (((sig_n_prime.w[1] == 0)
805 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
809 // adjust the y significand upwards
810 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
811 mult_factor[exp_y - exp_x]);
812 // return 0 if values are equal
813 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
817 // if positive, return whichever significand abs is smaller
818 // (converse if negative)
819 res = (((sig_n_prime.w[1] > 0)
820 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
825 #if DECIMAL_CALL_BY_REFERENCE
827 __bid64_quiet_less_equal (int *pres, UINT64 * px,
829 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
835 __bid64_quiet_less_equal (UINT64 x,
836 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
843 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
846 // if either number is NAN, the comparison is unordered, rather than equal :
848 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
849 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
850 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
856 // if all the bits are the same, these numbers are equal (LESSEQUAL).
862 if ((x & MASK_INF) == MASK_INF) {
863 if (((x & MASK_SIGN) == MASK_SIGN)) {
864 // if x is neg infinity, it must be lessthan or equal to y return 1
868 // x is pos infinity, it is greater, unless y is positive infinity =>
869 // return y==pos_infinity
870 res = !(((y & MASK_INF) != MASK_INF)
871 || ((y & MASK_SIGN) == MASK_SIGN));
874 } else if ((y & MASK_INF) == MASK_INF) {
875 // x is finite, so if y is positive infinity, then x is less, return 1
876 // if y is negative infinity, then x is greater, return 0
877 res = ((y & MASK_SIGN) != MASK_SIGN);
880 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
881 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
882 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
883 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
884 if (sig_x > 9999999999999999ull) {
890 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
891 sig_x = (x & MASK_BINARY_SIG1);
894 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
895 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
896 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
897 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
898 if (sig_y > 9999999999999999ull) {
904 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
905 sig_y = (y & MASK_BINARY_SIG1);
910 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
911 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
912 // therefore ignore the exponent field
913 // (Any non-canonical # is considered 0)
914 if (non_canon_x || sig_x == 0) {
917 if (non_canon_y || sig_y == 0) {
920 if (x_is_zero && y_is_zero) {
921 // if both numbers are zero, they are equal -> return 1
924 } else if (x_is_zero) {
925 // if x is zero, it is lessthan if Y is positive
926 res = ((y & MASK_SIGN) != MASK_SIGN);
928 } else if (y_is_zero) {
929 // if y is zero, X is less if it is negative
930 res = ((x & MASK_SIGN) == MASK_SIGN);
933 // OPPOSITE SIGN (CASE5)
934 // now, if the sign bits differ, x is less than if y is positive
935 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
936 res = ((y & MASK_SIGN) != MASK_SIGN);
939 // REDUNDANT REPRESENTATIONS (CASE6)
940 // if both components are either bigger or smaller
941 if (sig_x > sig_y && exp_x >= exp_y) {
942 res = ((x & MASK_SIGN) == MASK_SIGN);
945 if (sig_x < sig_y && exp_x <= exp_y) {
946 res = ((x & MASK_SIGN) != MASK_SIGN);
949 // if exp_x is 15 greater than exp_y, no need for compensation
950 if (exp_x - exp_y > 15) {
951 res = ((x & MASK_SIGN) == MASK_SIGN);
952 // difference cannot be greater than 10^15
955 // if exp_x is 15 less than exp_y, no need for compensation
956 if (exp_y - exp_x > 15) {
957 res = ((x & MASK_SIGN) != MASK_SIGN);
960 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
961 if (exp_x > exp_y) { // to simplify the loop below,
962 // otherwise adjust the x significand upwards
963 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
964 mult_factor[exp_x - exp_y]);
965 // return 1 if values are equal
966 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
970 // if postitive, return whichever significand abs is smaller
971 // (converse if negative)
972 res = (((sig_n_prime.w[1] == 0)
973 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
977 // adjust the y significand upwards
978 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
979 mult_factor[exp_y - exp_x]);
980 // return 1 if values are equal
981 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
985 // if positive, return whichever significand abs is smaller
986 // (converse if negative)
987 res = (((sig_n_prime.w[1] > 0)
988 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
993 #if DECIMAL_CALL_BY_REFERENCE
995 __bid64_quiet_less_unordered (int *pres, UINT64 * px,
997 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1003 __bid64_quiet_less_unordered (UINT64 x,
1004 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1009 UINT64 sig_x, sig_y;
1010 UINT128 sig_n_prime;
1011 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1014 // if either number is NAN, the comparison is unordered : return 0
1015 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1016 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1017 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1023 // if all the bits are the same, these numbers are equal.
1029 if ((x & MASK_INF) == MASK_INF) {
1030 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
1031 if ((x & MASK_SIGN) == MASK_SIGN) {
1032 // x is -inf, so it is less than y unless y is -inf
1033 res = (((y & MASK_INF) != MASK_INF)
1034 || (y & MASK_SIGN) != MASK_SIGN);
1037 // x is pos_inf, no way for it to be less than y
1041 } else if ((y & MASK_INF) == MASK_INF) {
1043 // if y is +inf, x<y
1044 // if y is -inf, x>y
1045 res = ((y & MASK_SIGN) != MASK_SIGN);
1048 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1049 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1050 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1051 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1052 if (sig_x > 9999999999999999ull) {
1058 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1059 sig_x = (x & MASK_BINARY_SIG1);
1062 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1063 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1064 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1065 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1066 if (sig_y > 9999999999999999ull) {
1072 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1073 sig_y = (y & MASK_BINARY_SIG1);
1078 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1079 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1080 // therefore ignore the exponent field
1081 // (Any non-canonical # is considered 0)
1082 if (non_canon_x || sig_x == 0) {
1085 if (non_canon_y || sig_y == 0) {
1088 if (x_is_zero && y_is_zero) {
1089 // if both numbers are zero, they are equal
1092 } else if (x_is_zero) {
1093 // if x is zero, it is lessthan if Y is positive
1094 res = ((y & MASK_SIGN) != MASK_SIGN);
1096 } else if (y_is_zero) {
1097 // if y is zero, X is less if it is negative
1098 res = ((x & MASK_SIGN) == MASK_SIGN);
1101 // OPPOSITE SIGN (CASE5)
1102 // now, if the sign bits differ, x is less than if y is positive
1103 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1104 res = ((y & MASK_SIGN) != MASK_SIGN);
1107 // REDUNDANT REPRESENTATIONS (CASE6)
1108 // if both components are either bigger or smaller
1109 if (sig_x > sig_y && exp_x >= exp_y) {
1110 res = ((x & MASK_SIGN) == MASK_SIGN);
1113 if (sig_x < sig_y && exp_x <= exp_y) {
1114 res = ((x & MASK_SIGN) != MASK_SIGN);
1117 // if exp_x is 15 greater than exp_y, no need for compensation
1118 if (exp_x - exp_y > 15) {
1119 res = ((x & MASK_SIGN) == MASK_SIGN);
1120 // difference cannot be greater than 10^15
1123 // if exp_x is 15 less than exp_y, no need for compensation
1124 if (exp_y - exp_x > 15) {
1125 res = ((x & MASK_SIGN) != MASK_SIGN);
1128 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1129 if (exp_x > exp_y) { // to simplify the loop below,
1130 // otherwise adjust the x significand upwards
1131 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1132 mult_factor[exp_x - exp_y]);
1133 // return 0 if values are equal
1134 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1138 // if postitive, return whichever significand abs is smaller
1139 // (converse if negative)
1140 res = (((sig_n_prime.w[1] == 0)
1141 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
1145 // adjust the y significand upwards
1146 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1147 mult_factor[exp_y - exp_x]);
1148 // return 0 if values are equal
1149 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1153 // if positive, return whichever significand abs is smaller
1154 // (converse if negative)
1155 res = (((sig_n_prime.w[1] > 0)
1156 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
1161 #if DECIMAL_CALL_BY_REFERENCE
1163 __bid64_quiet_not_equal (int *pres, UINT64 * px,
1165 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1171 __bid64_quiet_not_equal (UINT64 x,
1172 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1176 int exp_x, exp_y, exp_t;
1177 UINT64 sig_x, sig_y, sig_t;
1178 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y, lcv;
1181 // if either number is NAN, the comparison is unordered,
1182 // rather than equal : return 1
1183 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1184 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1185 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1191 // if all the bits are the same, these numbers are equivalent.
1197 if (((x & MASK_INF) == MASK_INF) && ((y & MASK_INF) == MASK_INF)) {
1198 res = (((x ^ y) & MASK_SIGN) == MASK_SIGN);
1201 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1202 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1203 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1204 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1205 if (sig_x > 9999999999999999ull) {
1211 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1212 sig_x = (x & MASK_BINARY_SIG1);
1216 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1217 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1218 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1219 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1220 if (sig_y > 9999999999999999ull) {
1226 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1227 sig_y = (y & MASK_BINARY_SIG1);
1233 // (+ZERO==-ZERO) => therefore ignore the sign
1234 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1235 // therefore ignore the exponent field
1236 // (Any non-canonical # is considered 0)
1237 if (non_canon_x || sig_x == 0) {
1240 if (non_canon_y || sig_y == 0) {
1244 if (x_is_zero && y_is_zero) {
1247 } else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
1251 // OPPOSITE SIGN (CASE5)
1252 // now, if the sign bits differ => not equal : return 1
1253 if ((x ^ y) & MASK_SIGN) {
1257 // REDUNDANT REPRESENTATIONS (CASE6)
1258 if (exp_x > exp_y) { // to simplify the loop below,
1259 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
1260 SWAP (sig_x, sig_y, sig_t); // and the smaller exp in x
1263 if (exp_y - exp_x > 15) {
1267 // difference cannot be greater than 10^16
1269 for (lcv = 0; lcv < (exp_y - exp_x); lcv++) {
1271 // recalculate y's significand upwards
1273 if (sig_y > 9999999999999999ull) {
1280 res = sig_y != sig_x;
1286 #if DECIMAL_CALL_BY_REFERENCE
1288 __bid64_quiet_not_greater (int *pres, UINT64 * px,
1290 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1296 __bid64_quiet_not_greater (UINT64 x,
1297 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1302 UINT64 sig_x, sig_y;
1303 UINT128 sig_n_prime;
1304 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1307 // if either number is NAN, the comparison is unordered,
1308 // rather than equal : return 0
1309 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1310 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1311 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1317 // if all the bits are the same, these numbers are equal (LESSEQUAL).
1323 if ((x & MASK_INF) == MASK_INF) {
1324 // if x is neg infinity, it must be lessthan or equal to y return 1
1325 if (((x & MASK_SIGN) == MASK_SIGN)) {
1329 // x is pos infinity, it is greater, unless y is positive
1330 // infinity => return y==pos_infinity
1332 res = !(((y & MASK_INF) != MASK_INF)
1333 || ((y & MASK_SIGN) == MASK_SIGN));
1336 } else if ((y & MASK_INF) == MASK_INF) {
1337 // x is finite, so if y is positive infinity, then x is less, return 1
1338 // if y is negative infinity, then x is greater, return 0
1340 res = ((y & MASK_SIGN) != MASK_SIGN);
1344 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1345 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1346 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1347 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1348 if (sig_x > 9999999999999999ull) {
1354 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1355 sig_x = (x & MASK_BINARY_SIG1);
1359 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1360 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1361 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1362 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1363 if (sig_y > 9999999999999999ull) {
1369 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1370 sig_y = (y & MASK_BINARY_SIG1);
1376 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1377 // number is greater
1378 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1379 // therefore ignore the exponent field
1380 // (Any non-canonical # is considered 0)
1381 if (non_canon_x || sig_x == 0) {
1384 if (non_canon_y || sig_y == 0) {
1387 // if both numbers are zero, they are equal -> return 1
1388 if (x_is_zero && y_is_zero) {
1392 // if x is zero, it is lessthan if Y is positive
1393 else if (x_is_zero) {
1394 res = ((y & MASK_SIGN) != MASK_SIGN);
1397 // if y is zero, X is less if it is negative
1398 else if (y_is_zero) {
1399 res = ((x & MASK_SIGN) == MASK_SIGN);
1402 // OPPOSITE SIGN (CASE5)
1403 // now, if the sign bits differ, x is less than if y is positive
1404 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1405 res = ((y & MASK_SIGN) != MASK_SIGN);
1408 // REDUNDANT REPRESENTATIONS (CASE6)
1409 // if both components are either bigger or smaller
1410 if (sig_x > sig_y && exp_x >= exp_y) {
1411 res = ((x & MASK_SIGN) == MASK_SIGN);
1414 if (sig_x < sig_y && exp_x <= exp_y) {
1415 res = ((x & MASK_SIGN) != MASK_SIGN);
1418 // if exp_x is 15 greater than exp_y, no need for compensation
1419 if (exp_x - exp_y > 15) {
1420 res = ((x & MASK_SIGN) == MASK_SIGN);
1423 // difference cannot be greater than 10^15
1425 // if exp_x is 15 less than exp_y, no need for compensation
1426 if (exp_y - exp_x > 15) {
1427 res = ((x & MASK_SIGN) != MASK_SIGN);
1430 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1431 if (exp_x > exp_y) { // to simplify the loop below,
1433 // otherwise adjust the x significand upwards
1434 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1435 mult_factor[exp_x - exp_y]);
1437 // return 1 if values are equal
1438 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1442 // if postitive, return whichever significand abs is smaller
1443 // (converse if negative)
1445 res = (((sig_n_prime.w[1] == 0)
1446 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
1451 // adjust the y significand upwards
1452 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1453 mult_factor[exp_y - exp_x]);
1455 // return 1 if values are equal
1456 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1460 // if positive, return whichever significand abs is smaller
1461 // (converse if negative)
1463 res = (((sig_n_prime.w[1] > 0)
1464 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
1470 #if DECIMAL_CALL_BY_REFERENCE
1472 __bid64_quiet_not_less (int *pres, UINT64 * px,
1474 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1480 __bid64_quiet_not_less (UINT64 x,
1481 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1486 UINT64 sig_x, sig_y;
1487 UINT128 sig_n_prime;
1488 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1491 // if either number is NAN, the comparison is unordered : return 1
1492 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1493 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1494 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1500 // if all the bits are the same, these numbers are equal.
1506 if ((x & MASK_INF) == MASK_INF) {
1507 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1508 if ((x & MASK_SIGN) == MASK_SIGN)
1509 // x is -inf, so it is less than y unless y is -inf
1511 res = (((y & MASK_INF) == MASK_INF)
1512 && (y & MASK_SIGN) == MASK_SIGN);
1515 // x is pos_inf, no way for it to be less than y
1520 } else if ((y & MASK_INF) == MASK_INF) {
1522 // if y is +inf, x<y
1523 // if y is -inf, x>y
1525 res = ((y & MASK_SIGN) == MASK_SIGN);
1529 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1530 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1531 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1532 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1533 if (sig_x > 9999999999999999ull) {
1539 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1540 sig_x = (x & MASK_BINARY_SIG1);
1544 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1545 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1546 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1547 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1548 if (sig_y > 9999999999999999ull) {
1554 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1555 sig_y = (y & MASK_BINARY_SIG1);
1561 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1562 // number is greater
1563 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1564 // therefore ignore the exponent field
1565 // (Any non-canonical # is considered 0)
1566 if (non_canon_x || sig_x == 0) {
1569 if (non_canon_y || sig_y == 0) {
1572 // if both numbers are zero, they are equal
1573 if (x_is_zero && y_is_zero) {
1577 // if x is zero, it is lessthan if Y is positive
1578 else if (x_is_zero) {
1579 res = ((y & MASK_SIGN) == MASK_SIGN);
1582 // if y is zero, X is less if it is negative
1583 else if (y_is_zero) {
1584 res = ((x & MASK_SIGN) != MASK_SIGN);
1587 // OPPOSITE SIGN (CASE5)
1588 // now, if the sign bits differ, x is less than if y is positive
1589 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1590 res = ((y & MASK_SIGN) == MASK_SIGN);
1593 // REDUNDANT REPRESENTATIONS (CASE6)
1594 // if both components are either bigger or smaller
1595 if (sig_x > sig_y && exp_x >= exp_y) {
1596 res = ((x & MASK_SIGN) != MASK_SIGN);
1599 if (sig_x < sig_y && exp_x <= exp_y) {
1600 res = ((x & MASK_SIGN) == MASK_SIGN);
1603 // if exp_x is 15 greater than exp_y, no need for compensation
1604 if (exp_x - exp_y > 15) {
1605 res = ((x & MASK_SIGN) != MASK_SIGN);
1608 // difference cannot be greater than 10^15
1610 // if exp_x is 15 less than exp_y, no need for compensation
1611 if (exp_y - exp_x > 15) {
1612 res = ((x & MASK_SIGN) == MASK_SIGN);
1615 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1616 if (exp_x > exp_y) { // to simplify the loop below,
1618 // otherwise adjust the x significand upwards
1619 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1620 mult_factor[exp_x - exp_y]);
1622 // return 0 if values are equal
1623 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1627 // if postitive, return whichever significand abs is smaller
1628 // (converse if negative)
1630 res = (((sig_n_prime.w[1] == 0)
1631 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
1636 // adjust the y significand upwards
1637 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1638 mult_factor[exp_y - exp_x]);
1640 // return 0 if values are equal
1641 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1645 // if positive, return whichever significand abs is smaller
1646 // (converse if negative)
1648 res = (((sig_n_prime.w[1] > 0)
1649 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
1655 #if DECIMAL_CALL_BY_REFERENCE
1657 __bid64_quiet_ordered (int *pres, UINT64 * px,
1659 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1665 __bid64_quiet_ordered (UINT64 x,
1666 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1672 // if either number is NAN, the comparison is ordered, rather than equal : return 0
1673 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1674 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1675 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1685 #if DECIMAL_CALL_BY_REFERENCE
1687 __bid64_quiet_unordered (int *pres, UINT64 * px,
1689 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1695 __bid64_quiet_unordered (UINT64 x,
1696 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1702 // if either number is NAN, the comparison is unordered,
1703 // rather than equal : return 0
1704 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1705 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1706 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1716 #if DECIMAL_CALL_BY_REFERENCE
1718 __bid64_signaling_equal (int *pres, UINT64 * px,
1720 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1726 __bid64_signaling_equal (UINT64 x,
1727 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1731 int exp_x, exp_y, exp_t;
1732 UINT64 sig_x, sig_y, sig_t;
1733 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y, lcv;
1736 // if either number is NAN, the comparison is unordered,
1737 // rather than equal : return 0
1738 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1739 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
1744 // if all the bits are the same, these numbers are equivalent.
1750 if (((x & MASK_INF) == MASK_INF) && ((y & MASK_INF) == MASK_INF)) {
1751 res = (((x ^ y) & MASK_SIGN) != MASK_SIGN);
1754 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1755 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1756 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1757 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1758 if (sig_x > 9999999999999999ull) {
1764 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1765 sig_x = (x & MASK_BINARY_SIG1);
1769 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1770 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1771 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1772 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1773 if (sig_y > 9999999999999999ull) {
1779 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1780 sig_y = (y & MASK_BINARY_SIG1);
1786 // (+ZERO==-ZERO) => therefore ignore the sign
1787 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1788 // therefore ignore the exponent field
1789 // (Any non-canonical # is considered 0)
1790 if (non_canon_x || sig_x == 0) {
1793 if (non_canon_y || sig_y == 0) {
1797 if (x_is_zero && y_is_zero) {
1800 } else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
1804 // OPPOSITE SIGN (CASE5)
1805 // now, if the sign bits differ => not equal : return 0
1806 if ((x ^ y) & MASK_SIGN) {
1810 // REDUNDANT REPRESENTATIONS (CASE6)
1811 if (exp_x > exp_y) { // to simplify the loop below,
1812 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
1813 SWAP (sig_x, sig_y, sig_t); // and the smaller exp in x
1816 if (exp_y - exp_x > 15) {
1820 // difference cannot be greater than 10^15
1822 for (lcv = 0; lcv < (exp_y - exp_x); lcv++) {
1824 // recalculate y's significand upwards
1826 if (sig_y > 9999999999999999ull) {
1833 res = sig_y == sig_x;
1839 #if DECIMAL_CALL_BY_REFERENCE
1841 __bid64_signaling_greater (int *pres, UINT64 * px,
1843 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1849 __bid64_signaling_greater (UINT64 x,
1850 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1855 UINT64 sig_x, sig_y;
1856 UINT128 sig_n_prime;
1857 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1860 // if either number is NAN, the comparison is unordered,
1861 // rather than equal : return 0
1862 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1863 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
1868 // if all the bits are the same, these numbers are equal (not Greater).
1874 if ((x & MASK_INF) == MASK_INF) {
1875 // if x is neg infinity, there is no way it is greater than y, return 0
1876 if (((x & MASK_SIGN) == MASK_SIGN)) {
1880 // x is pos infinity, it is greater,
1881 // unless y is positive infinity => return y!=pos_infinity
1883 res = (((y & MASK_INF) != MASK_INF)
1884 || ((y & MASK_SIGN) == MASK_SIGN));
1887 } else if ((y & MASK_INF) == MASK_INF) {
1888 // x is finite, so if y is positive infinity, then x is less, return 0
1889 // if y is negative infinity, then x is greater, return 1
1891 res = ((y & MASK_SIGN) == MASK_SIGN);
1895 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1896 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1897 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1898 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1899 if (sig_x > 9999999999999999ull) {
1905 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1906 sig_x = (x & MASK_BINARY_SIG1);
1910 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1911 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1912 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1913 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1914 if (sig_y > 9999999999999999ull) {
1920 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1921 sig_y = (y & MASK_BINARY_SIG1);
1927 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1928 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1929 // therefore ignore the exponent field
1930 // (Any non-canonical # is considered 0)
1931 if (non_canon_x || sig_x == 0) {
1934 if (non_canon_y || sig_y == 0) {
1937 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
1938 if (x_is_zero && y_is_zero) {
1942 // is x is zero, it is greater if Y is negative
1943 else if (x_is_zero) {
1944 res = ((y & MASK_SIGN) == MASK_SIGN);
1947 // is y is zero, X is greater if it is positive
1948 else if (y_is_zero) {
1949 res = ((x & MASK_SIGN) != MASK_SIGN);
1952 // OPPOSITE SIGN (CASE5)
1953 // now, if the sign bits differ, x is greater if y is negative
1954 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1955 res = ((y & MASK_SIGN) == MASK_SIGN);
1958 // REDUNDANT REPRESENTATIONS (CASE6)
1960 // if both components are either bigger or smaller
1961 if (sig_x > sig_y && exp_x >= exp_y) {
1962 res = ((x & MASK_SIGN) != MASK_SIGN);
1965 if (sig_x < sig_y && exp_x <= exp_y) {
1966 res = ((x & MASK_SIGN) == MASK_SIGN);
1969 // if exp_x is 15 greater than exp_y, no need for compensation
1970 if (exp_x - exp_y > 15) {
1971 res = ((x & MASK_SIGN) != MASK_SIGN);
1974 // difference cannot be greater than 10^15
1976 // if exp_x is 15 less than exp_y, no need for compensation
1977 if (exp_y - exp_x > 15) {
1978 res = ((x & MASK_SIGN) == MASK_SIGN);
1981 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1982 if (exp_x > exp_y) { // to simplify the loop below,
1984 // otherwise adjust the x significand upwards
1985 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1986 mult_factor[exp_x - exp_y]);
1989 // if postitive, return whichever significand is larger
1990 // (converse if negative)
1991 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1997 res = (((sig_n_prime.w[1] > 0)
1998 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
2003 // adjust the y significand upwards
2004 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2005 mult_factor[exp_y - exp_x]);
2007 // if postitive, return whichever significand is larger
2008 // (converse if negative)
2009 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2014 res = (((sig_n_prime.w[1] == 0)
2015 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2021 #if DECIMAL_CALL_BY_REFERENCE
2023 __bid64_signaling_greater_equal (int *pres, UINT64 * px,
2025 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2031 __bid64_signaling_greater_equal (UINT64 x,
2032 UINT64 y _EXC_FLAGS_PARAM
2033 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
2037 UINT64 sig_x, sig_y;
2038 UINT128 sig_n_prime;
2039 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2042 // if either number is NAN, the comparison is unordered : return 1
2043 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2044 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2049 // if all the bits are the same, these numbers are equal.
2055 if ((x & MASK_INF) == MASK_INF) {
2056 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
2057 if ((x & MASK_SIGN) == MASK_SIGN)
2058 // x is -inf, so it is less than y unless y is -inf
2060 res = (((y & MASK_INF) == MASK_INF)
2061 && (y & MASK_SIGN) == MASK_SIGN);
2064 // x is pos_inf, no way for it to be less than y
2069 } else if ((y & MASK_INF) == MASK_INF) {
2071 // if y is +inf, x<y
2072 // if y is -inf, x>y
2074 res = ((y & MASK_SIGN) == MASK_SIGN);
2078 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2079 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2080 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2081 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2082 if (sig_x > 9999999999999999ull) {
2088 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2089 sig_x = (x & MASK_BINARY_SIG1);
2093 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2094 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2095 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2096 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2097 if (sig_y > 9999999999999999ull) {
2103 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2104 sig_y = (y & MASK_BINARY_SIG1);
2110 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2111 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2112 // therefore ignore the exponent field
2113 // (Any non-canonical # is considered 0)
2114 if (non_canon_x || sig_x == 0) {
2117 if (non_canon_y || sig_y == 0) {
2120 // if both numbers are zero, they are equal
2121 if (x_is_zero && y_is_zero) {
2125 // if x is zero, it is lessthan if Y is positive
2126 else if (x_is_zero) {
2127 res = ((y & MASK_SIGN) == MASK_SIGN);
2130 // if y is zero, X is less if it is negative
2131 else if (y_is_zero) {
2132 res = ((x & MASK_SIGN) != MASK_SIGN);
2135 // OPPOSITE SIGN (CASE5)
2136 // now, if the sign bits differ, x is less than if y is positive
2137 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2138 res = ((y & MASK_SIGN) == MASK_SIGN);
2141 // REDUNDANT REPRESENTATIONS (CASE6)
2142 // if both components are either bigger or smaller
2143 if (sig_x > sig_y && exp_x >= exp_y) {
2144 res = ((x & MASK_SIGN) != MASK_SIGN);
2147 if (sig_x < sig_y && exp_x <= exp_y) {
2148 res = ((x & MASK_SIGN) == MASK_SIGN);
2151 // if exp_x is 15 greater than exp_y, no need for compensation
2152 if (exp_x - exp_y > 15) {
2153 res = ((x & MASK_SIGN) != MASK_SIGN);
2156 // difference cannot be greater than 10^15
2158 // if exp_x is 15 less than exp_y, no need for compensation
2159 if (exp_y - exp_x > 15) {
2160 res = ((x & MASK_SIGN) == MASK_SIGN);
2163 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2164 if (exp_x > exp_y) { // to simplify the loop below,
2166 // otherwise adjust the x significand upwards
2167 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2168 mult_factor[exp_x - exp_y]);
2170 // return 1 if values are equal
2171 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2175 // if postitive, return whichever significand abs is smaller
2176 // (converse if negative)
2178 res = (((sig_n_prime.w[1] == 0)
2179 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
2184 // adjust the y significand upwards
2185 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2186 mult_factor[exp_y - exp_x]);
2188 // return 0 if values are equal
2189 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2193 // if positive, return whichever significand abs is smaller
2194 // (converse if negative)
2196 res = (((sig_n_prime.w[1] > 0)
2197 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
2203 #if DECIMAL_CALL_BY_REFERENCE
2205 __bid64_signaling_greater_unordered (int *pres, UINT64 * px,
2207 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2213 __bid64_signaling_greater_unordered (UINT64 x,
2214 UINT64 y _EXC_FLAGS_PARAM
2215 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
2219 UINT64 sig_x, sig_y;
2220 UINT128 sig_n_prime;
2221 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2224 // if either number is NAN, the comparison is unordered,
2225 // rather than equal : return 0
2226 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2227 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2232 // if all the bits are the same, these numbers are equal (not Greater).
2238 if ((x & MASK_INF) == MASK_INF) {
2239 // if x is neg infinity, there is no way it is greater than y, return 0
2240 if (((x & MASK_SIGN) == MASK_SIGN)) {
2244 // x is pos infinity, it is greater,
2245 // unless y is positive infinity => return y!=pos_infinity
2247 res = (((y & MASK_INF) != MASK_INF)
2248 || ((y & MASK_SIGN) == MASK_SIGN));
2251 } else if ((y & MASK_INF) == MASK_INF) {
2252 // x is finite, so if y is positive infinity, then x is less, return 0
2253 // if y is negative infinity, then x is greater, return 1
2255 res = ((y & MASK_SIGN) == MASK_SIGN);
2259 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2260 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2261 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2262 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2263 if (sig_x > 9999999999999999ull) {
2269 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2270 sig_x = (x & MASK_BINARY_SIG1);
2274 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2275 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2276 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2277 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2278 if (sig_y > 9999999999999999ull) {
2284 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2285 sig_y = (y & MASK_BINARY_SIG1);
2291 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2292 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2293 // therefore ignore the exponent field
2294 // (Any non-canonical # is considered 0)
2295 if (non_canon_x || sig_x == 0) {
2298 if (non_canon_y || sig_y == 0) {
2301 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
2302 if (x_is_zero && y_is_zero) {
2306 // is x is zero, it is greater if Y is negative
2307 else if (x_is_zero) {
2308 res = ((y & MASK_SIGN) == MASK_SIGN);
2311 // is y is zero, X is greater if it is positive
2312 else if (y_is_zero) {
2313 res = ((x & MASK_SIGN) != MASK_SIGN);
2316 // OPPOSITE SIGN (CASE5)
2317 // now, if the sign bits differ, x is greater if y is negative
2318 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2319 res = ((y & MASK_SIGN) == MASK_SIGN);
2322 // REDUNDANT REPRESENTATIONS (CASE6)
2324 // if both components are either bigger or smaller
2325 if (sig_x > sig_y && exp_x >= exp_y) {
2326 res = ((x & MASK_SIGN) != MASK_SIGN);
2329 if (sig_x < sig_y && exp_x <= exp_y) {
2330 res = ((x & MASK_SIGN) == MASK_SIGN);
2333 // if exp_x is 15 greater than exp_y, no need for compensation
2334 if (exp_x - exp_y > 15) {
2335 res = ((x & MASK_SIGN) != MASK_SIGN);
2338 // difference cannot be greater than 10^15
2340 // if exp_x is 15 less than exp_y, no need for compensation
2341 if (exp_y - exp_x > 15) {
2342 res = ((x & MASK_SIGN) == MASK_SIGN);
2345 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2346 if (exp_x > exp_y) { // to simplify the loop below,
2348 // otherwise adjust the x significand upwards
2349 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2350 mult_factor[exp_x - exp_y]);
2352 // if postitive, return whichever significand is larger
2353 // (converse if negative)
2354 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2360 res = (((sig_n_prime.w[1] > 0)
2361 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
2366 // adjust the y significand upwards
2367 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2368 mult_factor[exp_y - exp_x]);
2370 // if postitive, return whichever significand is larger
2371 // (converse if negative)
2372 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2377 res = (((sig_n_prime.w[1] == 0)
2378 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2384 #if DECIMAL_CALL_BY_REFERENCE
2386 __bid64_signaling_less (int *pres, UINT64 * px,
2388 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2394 __bid64_signaling_less (UINT64 x,
2395 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2400 UINT64 sig_x, sig_y;
2401 UINT128 sig_n_prime;
2402 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2405 // if either number is NAN, the comparison is unordered : return 0
2406 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2407 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2412 // if all the bits are the same, these numbers are equal.
2418 if ((x & MASK_INF) == MASK_INF) {
2419 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2420 if ((x & MASK_SIGN) == MASK_SIGN)
2421 // x is -inf, so it is less than y unless y is -inf
2423 res = (((y & MASK_INF) != MASK_INF)
2424 || (y & MASK_SIGN) != MASK_SIGN);
2427 // x is pos_inf, no way for it to be less than y
2432 } else if ((y & MASK_INF) == MASK_INF) {
2434 // if y is +inf, x<y
2435 // if y is -inf, x>y
2437 res = ((y & MASK_SIGN) != MASK_SIGN);
2441 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2442 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2443 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2444 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2445 if (sig_x > 9999999999999999ull) {
2451 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2452 sig_x = (x & MASK_BINARY_SIG1);
2456 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2457 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2458 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2459 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2460 if (sig_y > 9999999999999999ull) {
2466 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2467 sig_y = (y & MASK_BINARY_SIG1);
2473 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2474 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2475 // therefore ignore the exponent field
2476 // (Any non-canonical # is considered 0)
2477 if (non_canon_x || sig_x == 0) {
2480 if (non_canon_y || sig_y == 0) {
2483 // if both numbers are zero, they are equal
2484 if (x_is_zero && y_is_zero) {
2488 // if x is zero, it is lessthan if Y is positive
2489 else if (x_is_zero) {
2490 res = ((y & MASK_SIGN) != MASK_SIGN);
2493 // if y is zero, X is less if it is negative
2494 else if (y_is_zero) {
2495 res = ((x & MASK_SIGN) == MASK_SIGN);
2498 // OPPOSITE SIGN (CASE5)
2499 // now, if the sign bits differ, x is less than if y is positive
2500 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2501 res = ((y & MASK_SIGN) != MASK_SIGN);
2504 // REDUNDANT REPRESENTATIONS (CASE6)
2505 // if both components are either bigger or smaller
2506 if (sig_x > sig_y && exp_x >= exp_y) {
2507 res = ((x & MASK_SIGN) == MASK_SIGN);
2510 if (sig_x < sig_y && exp_x <= exp_y) {
2511 res = ((x & MASK_SIGN) != MASK_SIGN);
2514 // if exp_x is 15 greater than exp_y, no need for compensation
2515 if (exp_x - exp_y > 15) {
2516 res = ((x & MASK_SIGN) == MASK_SIGN);
2519 // difference cannot be greater than 10^15
2521 // if exp_x is 15 less than exp_y, no need for compensation
2522 if (exp_y - exp_x > 15) {
2523 res = ((x & MASK_SIGN) != MASK_SIGN);
2526 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2527 if (exp_x > exp_y) { // to simplify the loop below,
2529 // otherwise adjust the x significand upwards
2530 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2531 mult_factor[exp_x - exp_y]);
2533 // return 0 if values are equal
2534 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2538 // if postitive, return whichever significand abs is smaller
2539 // (converse if negative)
2541 res = (((sig_n_prime.w[1] == 0)
2542 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2547 // adjust the y significand upwards
2548 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2549 mult_factor[exp_y - exp_x]);
2551 // return 0 if values are equal
2552 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2556 // if positive, return whichever significand abs is smaller
2557 // (converse if negative)
2559 res = (((sig_n_prime.w[1] > 0)
2560 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2566 #if DECIMAL_CALL_BY_REFERENCE
2568 __bid64_signaling_less_equal (int *pres, UINT64 * px,
2570 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2576 __bid64_signaling_less_equal (UINT64 x,
2577 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2582 UINT64 sig_x, sig_y;
2583 UINT128 sig_n_prime;
2584 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2587 // if either number is NAN, the comparison is unordered,
2588 // rather than equal : return 0
2589 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2590 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2595 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2601 if ((x & MASK_INF) == MASK_INF) {
2602 // if x is neg infinity, it must be lessthan or equal to y return 1
2603 if (((x & MASK_SIGN) == MASK_SIGN)) {
2607 // x is pos infinity, it is greater,
2608 // unless y is positive infinity => return y==pos_infinity
2610 res = !(((y & MASK_INF) != MASK_INF)
2611 || ((y & MASK_SIGN) == MASK_SIGN));
2614 } else if ((y & MASK_INF) == MASK_INF) {
2615 // x is finite, so if y is positive infinity, then x is less, return 1
2616 // if y is negative infinity, then x is greater, return 0
2618 res = ((y & MASK_SIGN) != MASK_SIGN);
2622 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2623 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2624 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2625 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2626 if (sig_x > 9999999999999999ull) {
2632 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2633 sig_x = (x & MASK_BINARY_SIG1);
2637 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2638 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2639 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2640 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2641 if (sig_y > 9999999999999999ull) {
2647 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2648 sig_y = (y & MASK_BINARY_SIG1);
2654 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2655 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2656 // therefore ignore the exponent field
2657 // (Any non-canonical # is considered 0)
2658 if (non_canon_x || sig_x == 0) {
2661 if (non_canon_y || sig_y == 0) {
2664 // if both numbers are zero, they are equal -> return 1
2665 if (x_is_zero && y_is_zero) {
2669 // if x is zero, it is lessthan if Y is positive
2670 else if (x_is_zero) {
2671 res = ((y & MASK_SIGN) != MASK_SIGN);
2674 // if y is zero, X is less if it is negative
2675 else if (y_is_zero) {
2676 res = ((x & MASK_SIGN) == MASK_SIGN);
2679 // OPPOSITE SIGN (CASE5)
2680 // now, if the sign bits differ, x is less than if y is positive
2681 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2682 res = ((y & MASK_SIGN) != MASK_SIGN);
2685 // REDUNDANT REPRESENTATIONS (CASE6)
2686 // if both components are either bigger or smaller
2687 if (sig_x > sig_y && exp_x >= exp_y) {
2688 res = ((x & MASK_SIGN) == MASK_SIGN);
2691 if (sig_x < sig_y && exp_x <= exp_y) {
2692 res = ((x & MASK_SIGN) != MASK_SIGN);
2695 // if exp_x is 15 greater than exp_y, no need for compensation
2696 if (exp_x - exp_y > 15) {
2697 res = ((x & MASK_SIGN) == MASK_SIGN);
2700 // difference cannot be greater than 10^15
2702 // if exp_x is 15 less than exp_y, no need for compensation
2703 if (exp_y - exp_x > 15) {
2704 res = ((x & MASK_SIGN) != MASK_SIGN);
2707 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2708 if (exp_x > exp_y) { // to simplify the loop below,
2710 // otherwise adjust the x significand upwards
2711 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2712 mult_factor[exp_x - exp_y]);
2714 // return 1 if values are equal
2715 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2719 // if postitive, return whichever significand abs is smaller
2720 // (converse if negative)
2722 res = (((sig_n_prime.w[1] == 0)
2723 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2728 // adjust the y significand upwards
2729 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2730 mult_factor[exp_y - exp_x]);
2732 // return 1 if values are equal
2733 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2737 // if positive, return whichever significand abs is smaller
2738 // (converse if negative)
2740 res = (((sig_n_prime.w[1] > 0)
2741 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2747 #if DECIMAL_CALL_BY_REFERENCE
2749 __bid64_signaling_less_unordered (int *pres, UINT64 * px,
2751 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2757 __bid64_signaling_less_unordered (UINT64 x,
2758 UINT64 y _EXC_FLAGS_PARAM
2759 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
2763 UINT64 sig_x, sig_y;
2764 UINT128 sig_n_prime;
2765 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2768 // if either number is NAN, the comparison is unordered : return 0
2769 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2770 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2775 // if all the bits are the same, these numbers are equal.
2781 if ((x & MASK_INF) == MASK_INF) {
2782 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2783 if ((x & MASK_SIGN) == MASK_SIGN)
2784 // x is -inf, so it is less than y unless y is -inf
2786 res = (((y & MASK_INF) != MASK_INF)
2787 || (y & MASK_SIGN) != MASK_SIGN);
2790 // x is pos_inf, no way for it to be less than y
2795 } else if ((y & MASK_INF) == MASK_INF) {
2797 // if y is +inf, x<y
2798 // if y is -inf, x>y
2800 res = ((y & MASK_SIGN) != MASK_SIGN);
2804 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2805 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2806 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2807 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2808 if (sig_x > 9999999999999999ull) {
2814 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2815 sig_x = (x & MASK_BINARY_SIG1);
2819 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2820 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2821 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2822 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2823 if (sig_y > 9999999999999999ull) {
2829 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2830 sig_y = (y & MASK_BINARY_SIG1);
2836 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2837 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2838 // therefore ignore the exponent field
2839 // (Any non-canonical # is considered 0)
2840 if (non_canon_x || sig_x == 0) {
2843 if (non_canon_y || sig_y == 0) {
2846 // if both numbers are zero, they are equal
2847 if (x_is_zero && y_is_zero) {
2851 // if x is zero, it is lessthan if Y is positive
2852 else if (x_is_zero) {
2853 res = ((y & MASK_SIGN) != MASK_SIGN);
2856 // if y is zero, X is less if it is negative
2857 else if (y_is_zero) {
2858 res = ((x & MASK_SIGN) == MASK_SIGN);
2861 // OPPOSITE SIGN (CASE5)
2862 // now, if the sign bits differ, x is less than if y is positive
2863 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2864 res = ((y & MASK_SIGN) != MASK_SIGN);
2867 // REDUNDANT REPRESENTATIONS (CASE6)
2868 // if both components are either bigger or smaller
2869 if (sig_x > sig_y && exp_x >= exp_y) {
2870 res = ((x & MASK_SIGN) == MASK_SIGN);
2873 if (sig_x < sig_y && exp_x <= exp_y) {
2874 res = ((x & MASK_SIGN) != MASK_SIGN);
2877 // if exp_x is 15 greater than exp_y, no need for compensation
2878 if (exp_x - exp_y > 15) {
2879 res = ((x & MASK_SIGN) == MASK_SIGN);
2882 // difference cannot be greater than 10^15
2884 // if exp_x is 15 less than exp_y, no need for compensation
2885 if (exp_y - exp_x > 15) {
2886 res = ((x & MASK_SIGN) != MASK_SIGN);
2889 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2890 if (exp_x > exp_y) { // to simplify the loop below,
2892 // otherwise adjust the x significand upwards
2893 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2894 mult_factor[exp_x - exp_y]);
2896 // return 0 if values are equal
2897 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2901 // if postitive, return whichever significand abs is smaller
2902 // (converse if negative)
2904 res = (((sig_n_prime.w[1] == 0)
2905 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2910 // adjust the y significand upwards
2911 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2912 mult_factor[exp_y - exp_x]);
2914 // return 0 if values are equal
2915 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2919 // if positive, return whichever significand abs is smaller
2920 // (converse if negative)
2922 res = (((sig_n_prime.w[1] > 0)
2923 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2929 #if DECIMAL_CALL_BY_REFERENCE
2931 __bid64_signaling_not_equal (int *pres, UINT64 * px,
2933 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2939 __bid64_signaling_not_equal (UINT64 x,
2940 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2944 int exp_x, exp_y, exp_t;
2945 UINT64 sig_x, sig_y, sig_t;
2946 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y, lcv;
2949 // if either number is NAN, the comparison is unordered,
2950 // rather than equal : return 1
2951 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2952 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2957 // if all the bits are the same, these numbers are equivalent.
2963 if (((x & MASK_INF) == MASK_INF) && ((y & MASK_INF) == MASK_INF)) {
2964 res = (((x ^ y) & MASK_SIGN) == MASK_SIGN);
2967 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2968 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2969 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2970 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2971 if (sig_x > 9999999999999999ull) {
2977 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2978 sig_x = (x & MASK_BINARY_SIG1);
2982 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2983 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2984 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2985 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2986 if (sig_y > 9999999999999999ull) {
2992 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2993 sig_y = (y & MASK_BINARY_SIG1);
2999 // (+ZERO==-ZERO) => therefore ignore the sign
3000 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
3001 // therefore ignore the exponent field
3002 // (Any non-canonical # is considered 0)
3003 if (non_canon_x || sig_x == 0) {
3006 if (non_canon_y || sig_y == 0) {
3010 if (x_is_zero && y_is_zero) {
3013 } else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
3017 // OPPOSITE SIGN (CASE5)
3018 // now, if the sign bits differ => not equal : return 1
3019 if ((x ^ y) & MASK_SIGN) {
3023 // REDUNDANT REPRESENTATIONS (CASE6)
3024 if (exp_x > exp_y) { // to simplify the loop below,
3025 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
3026 SWAP (sig_x, sig_y, sig_t); // and the smaller exp in x
3029 if (exp_y - exp_x > 15) {
3033 // difference cannot be greater than 10^16
3035 for (lcv = 0; lcv < (exp_y - exp_x); lcv++) {
3037 // recalculate y's significand upwards
3039 if (sig_y > 9999999999999999ull) {
3046 res = sig_y != sig_x;
3052 #if DECIMAL_CALL_BY_REFERENCE
3054 __bid64_signaling_not_greater (int *pres, UINT64 * px,
3056 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3062 __bid64_signaling_not_greater (UINT64 x,
3063 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3068 UINT64 sig_x, sig_y;
3069 UINT128 sig_n_prime;
3070 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
3073 // if either number is NAN, the comparison is unordered,
3074 // rather than equal : return 0
3075 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
3076 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
3081 // if all the bits are the same, these numbers are equal (LESSEQUAL).
3087 if ((x & MASK_INF) == MASK_INF) {
3088 // if x is neg infinity, it must be lessthan or equal to y return 1
3089 if (((x & MASK_SIGN) == MASK_SIGN)) {
3093 // x is pos infinity, it is greater,
3094 // unless y is positive infinity => return y==pos_infinity
3096 res = !(((y & MASK_INF) != MASK_INF)
3097 || ((y & MASK_SIGN) == MASK_SIGN));
3100 } else if ((y & MASK_INF) == MASK_INF) {
3101 // x is finite, so if y is positive infinity, then x is less, return 1
3102 // if y is negative infinity, then x is greater, return 0
3104 res = ((y & MASK_SIGN) != MASK_SIGN);
3108 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3109 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
3110 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
3111 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
3112 if (sig_x > 9999999999999999ull) {
3118 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
3119 sig_x = (x & MASK_BINARY_SIG1);
3123 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3124 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
3125 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
3126 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
3127 if (sig_y > 9999999999999999ull) {
3133 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
3134 sig_y = (y & MASK_BINARY_SIG1);
3140 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
3141 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
3142 // therefore ignore the exponent field
3143 // (Any non-canonical # is considered 0)
3144 if (non_canon_x || sig_x == 0) {
3147 if (non_canon_y || sig_y == 0) {
3150 // if both numbers are zero, they are equal -> return 1
3151 if (x_is_zero && y_is_zero) {
3155 // if x is zero, it is lessthan if Y is positive
3156 else if (x_is_zero) {
3157 res = ((y & MASK_SIGN) != MASK_SIGN);
3160 // if y is zero, X is less if it is negative
3161 else if (y_is_zero) {
3162 res = ((x & MASK_SIGN) == MASK_SIGN);
3165 // OPPOSITE SIGN (CASE5)
3166 // now, if the sign bits differ, x is less than if y is positive
3167 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
3168 res = ((y & MASK_SIGN) != MASK_SIGN);
3171 // REDUNDANT REPRESENTATIONS (CASE6)
3172 // if both components are either bigger or smaller
3173 if (sig_x > sig_y && exp_x >= exp_y) {
3174 res = ((x & MASK_SIGN) == MASK_SIGN);
3177 if (sig_x < sig_y && exp_x <= exp_y) {
3178 res = ((x & MASK_SIGN) != MASK_SIGN);
3181 // if exp_x is 15 greater than exp_y, no need for compensation
3182 if (exp_x - exp_y > 15) {
3183 res = ((x & MASK_SIGN) == MASK_SIGN);
3186 // difference cannot be greater than 10^15
3188 // if exp_x is 15 less than exp_y, no need for compensation
3189 if (exp_y - exp_x > 15) {
3190 res = ((x & MASK_SIGN) != MASK_SIGN);
3193 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
3194 if (exp_x > exp_y) { // to simplify the loop below,
3196 // otherwise adjust the x significand upwards
3197 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
3198 mult_factor[exp_x - exp_y]);
3200 // return 1 if values are equal
3201 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
3205 // if postitive, return whichever significand abs is smaller
3206 // (converse if negative)
3208 res = (((sig_n_prime.w[1] == 0)
3209 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
3214 // adjust the y significand upwards
3215 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
3216 mult_factor[exp_y - exp_x]);
3218 // return 1 if values are equal
3219 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
3223 // if positive, return whichever significand abs is smaller
3224 // (converse if negative)
3226 res = (((sig_n_prime.w[1] > 0)
3227 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
3233 #if DECIMAL_CALL_BY_REFERENCE
3235 __bid64_signaling_not_less (int *pres, UINT64 * px,
3237 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3243 __bid64_signaling_not_less (UINT64 x,
3244 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3249 UINT64 sig_x, sig_y;
3250 UINT128 sig_n_prime;
3251 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
3254 // if either number is NAN, the comparison is unordered : return 1
3255 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
3256 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
3261 // if all the bits are the same, these numbers are equal.
3267 if ((x & MASK_INF) == MASK_INF) {
3268 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
3269 if ((x & MASK_SIGN) == MASK_SIGN)
3270 // x is -inf, so it is less than y unless y is -inf
3272 res = (((y & MASK_INF) == MASK_INF)
3273 && (y & MASK_SIGN) == MASK_SIGN);
3276 // x is pos_inf, no way for it to be less than y
3281 } else if ((y & MASK_INF) == MASK_INF) {
3283 // if y is +inf, x<y
3284 // if y is -inf, x>y
3286 res = ((y & MASK_SIGN) == MASK_SIGN);
3290 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3291 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
3292 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
3293 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
3294 if (sig_x > 9999999999999999ull) {
3300 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
3301 sig_x = (x & MASK_BINARY_SIG1);
3305 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3306 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
3307 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
3308 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
3309 if (sig_y > 9999999999999999ull) {
3315 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
3316 sig_y = (y & MASK_BINARY_SIG1);
3322 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
3323 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
3324 // therefore ignore the exponent field
3325 // (Any non-canonical # is considered 0)
3326 if (non_canon_x || sig_x == 0) {
3329 if (non_canon_y || sig_y == 0) {
3332 // if both numbers are zero, they are equal
3333 if (x_is_zero && y_is_zero) {
3337 // if x is zero, it is lessthan if Y is positive
3338 else if (x_is_zero) {
3339 res = ((y & MASK_SIGN) == MASK_SIGN);
3342 // if y is zero, X is less if it is negative
3343 else if (y_is_zero) {
3344 res = ((x & MASK_SIGN) != MASK_SIGN);
3347 // OPPOSITE SIGN (CASE5)
3348 // now, if the sign bits differ, x is less than if y is positive
3349 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
3350 res = ((y & MASK_SIGN) == MASK_SIGN);
3353 // REDUNDANT REPRESENTATIONS (CASE6)
3354 // if both components are either bigger or smaller
3355 if (sig_x > sig_y && exp_x >= exp_y) {
3356 res = ((x & MASK_SIGN) != MASK_SIGN);
3359 if (sig_x < sig_y && exp_x <= exp_y) {
3360 res = ((x & MASK_SIGN) == MASK_SIGN);
3363 // if exp_x is 15 greater than exp_y, no need for compensation
3364 if (exp_x - exp_y > 15) {
3365 res = ((x & MASK_SIGN) != MASK_SIGN);
3368 // difference cannot be greater than 10^15
3370 // if exp_x is 15 less than exp_y, no need for compensation
3371 if (exp_y - exp_x > 15) {
3372 res = ((x & MASK_SIGN) == MASK_SIGN);
3375 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
3376 if (exp_x > exp_y) { // to simplify the loop below,
3378 // otherwise adjust the x significand upwards
3379 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
3380 mult_factor[exp_x - exp_y]);
3382 // return 0 if values are equal
3383 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
3387 // if postitive, return whichever significand abs is smaller
3388 // (converse if negative)
3390 res = (((sig_n_prime.w[1] == 0)
3391 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
3396 // adjust the y significand upwards
3397 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
3398 mult_factor[exp_y - exp_x]);
3400 // return 0 if values are equal
3401 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
3405 // if positive, return whichever significand abs is smaller
3406 // (converse if negative)
3408 res = (((sig_n_prime.w[1] > 0)
3409 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
3415 #if DECIMAL_CALL_BY_REFERENCE
3417 __bid64_signaling_ordered (int *pres, UINT64 * px,
3419 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3425 __bid64_signaling_ordered (UINT64 x,
3426 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3432 // if either number is NAN, the comparison is ordered,
3433 // rather than equal : return 0
3434 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
3435 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
3444 #if DECIMAL_CALL_BY_REFERENCE
3446 __bid64_signaling_unordered (int *pres, UINT64 * px,
3448 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3454 __bid64_signaling_unordered (UINT64 x,
3455 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3461 // if either number is NAN, the comparison is unordered,
3462 // rather than equal : return 0
3463 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
3464 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN