1 /* Copyright (C) 2007-2017 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 3, or (at your option) any later
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #include "bid_internal.h"
26 static const UINT64 mult_factor
[16] = {
27 1ull, 10ull, 100ull, 1000ull,
28 10000ull, 100000ull, 1000000ull, 10000000ull,
29 100000000ull, 1000000000ull, 10000000000ull, 100000000000ull,
30 1000000000000ull, 10000000000000ull,
31 100000000000000ull, 1000000000000000ull
34 #if DECIMAL_CALL_BY_REFERENCE
36 bid64_quiet_equal (int *pres
, UINT64
* px
,
38 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
44 bid64_quiet_equal (UINT64 x
,
45 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
49 int exp_x
, exp_y
, exp_t
;
50 UINT64 sig_x
, sig_y
, sig_t
;
51 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
, lcv
;
54 // if either number is NAN, the comparison is unordered,
55 // rather than equal : return 0
56 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
57 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
58 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
64 // if all the bits are the same, these numbers are equivalent.
70 if (((x
& MASK_INF
) == MASK_INF
) && ((y
& MASK_INF
) == MASK_INF
)) {
71 res
= (((x
^ y
) & MASK_SIGN
) != MASK_SIGN
);
74 // ONE INFINITY (CASE3')
75 if (((x
& MASK_INF
) == MASK_INF
) || ((y
& MASK_INF
) == MASK_INF
)) {
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 // ONE INFINITY (CASE3')
1202 if (((x
& MASK_INF
) == MASK_INF
) || ((y
& MASK_INF
) == MASK_INF
)) {
1206 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1207 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1208 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1209 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1210 if (sig_x
> 9999999999999999ull) {
1216 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1217 sig_x
= (x
& MASK_BINARY_SIG1
);
1221 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1222 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1223 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1224 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1225 if (sig_y
> 9999999999999999ull) {
1231 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1232 sig_y
= (y
& MASK_BINARY_SIG1
);
1238 // (+ZERO==-ZERO) => therefore ignore the sign
1239 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1240 // therefore ignore the exponent field
1241 // (Any non-canonical # is considered 0)
1242 if (non_canon_x
|| sig_x
== 0) {
1245 if (non_canon_y
|| sig_y
== 0) {
1249 if (x_is_zero
&& y_is_zero
) {
1252 } else if ((x_is_zero
&& !y_is_zero
) || (!x_is_zero
&& y_is_zero
)) {
1256 // OPPOSITE SIGN (CASE5)
1257 // now, if the sign bits differ => not equal : return 1
1258 if ((x
^ y
) & MASK_SIGN
) {
1262 // REDUNDANT REPRESENTATIONS (CASE6)
1263 if (exp_x
> exp_y
) { // to simplify the loop below,
1264 SWAP (exp_x
, exp_y
, exp_t
); // put the larger exp in y,
1265 SWAP (sig_x
, sig_y
, sig_t
); // and the smaller exp in x
1268 if (exp_y
- exp_x
> 15) {
1272 // difference cannot be greater than 10^16
1274 for (lcv
= 0; lcv
< (exp_y
- exp_x
); lcv
++) {
1276 // recalculate y's significand upwards
1278 if (sig_y
> 9999999999999999ull) {
1285 res
= sig_y
!= sig_x
;
1291 #if DECIMAL_CALL_BY_REFERENCE
1293 bid64_quiet_not_greater (int *pres
, UINT64
* px
,
1295 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1301 bid64_quiet_not_greater (UINT64 x
,
1302 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1307 UINT64 sig_x
, sig_y
;
1308 UINT128 sig_n_prime
;
1309 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1312 // if either number is NAN, the comparison is unordered,
1313 // rather than equal : return 0
1314 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1315 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1316 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1322 // if all the bits are the same, these numbers are equal (LESSEQUAL).
1328 if ((x
& MASK_INF
) == MASK_INF
) {
1329 // if x is neg infinity, it must be lessthan or equal to y return 1
1330 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
1334 // x is pos infinity, it is greater, unless y is positive
1335 // infinity => return y==pos_infinity
1337 res
= !(((y
& MASK_INF
) != MASK_INF
)
1338 || ((y
& MASK_SIGN
) == MASK_SIGN
));
1341 } else if ((y
& MASK_INF
) == MASK_INF
) {
1342 // x is finite, so if y is positive infinity, then x is less, return 1
1343 // if y is negative infinity, then x is greater, return 0
1345 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1349 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1350 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1351 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1352 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1353 if (sig_x
> 9999999999999999ull) {
1359 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1360 sig_x
= (x
& MASK_BINARY_SIG1
);
1364 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1365 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1366 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1367 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1368 if (sig_y
> 9999999999999999ull) {
1374 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1375 sig_y
= (y
& MASK_BINARY_SIG1
);
1381 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1382 // number is greater
1383 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1384 // therefore ignore the exponent field
1385 // (Any non-canonical # is considered 0)
1386 if (non_canon_x
|| sig_x
== 0) {
1389 if (non_canon_y
|| sig_y
== 0) {
1392 // if both numbers are zero, they are equal -> return 1
1393 if (x_is_zero
&& y_is_zero
) {
1397 // if x is zero, it is lessthan if Y is positive
1398 else if (x_is_zero
) {
1399 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1402 // if y is zero, X is less if it is negative
1403 else if (y_is_zero
) {
1404 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1407 // OPPOSITE SIGN (CASE5)
1408 // now, if the sign bits differ, x is less than if y is positive
1409 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1410 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1413 // REDUNDANT REPRESENTATIONS (CASE6)
1414 // if both components are either bigger or smaller
1415 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1416 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1419 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1420 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1423 // if exp_x is 15 greater than exp_y, no need for compensation
1424 if (exp_x
- exp_y
> 15) {
1425 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1428 // difference cannot be greater than 10^15
1430 // if exp_x is 15 less than exp_y, no need for compensation
1431 if (exp_y
- exp_x
> 15) {
1432 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1435 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1436 if (exp_x
> exp_y
) { // to simplify the loop below,
1438 // otherwise adjust the x significand upwards
1439 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1440 mult_factor
[exp_x
- exp_y
]);
1442 // return 1 if values are equal
1443 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1447 // if postitive, return whichever significand abs is smaller
1448 // (converse if negative)
1450 res
= (((sig_n_prime
.w
[1] == 0)
1451 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
1456 // adjust the y significand upwards
1457 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1458 mult_factor
[exp_y
- exp_x
]);
1460 // return 1 if values are equal
1461 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1465 // if positive, return whichever significand abs is smaller
1466 // (converse if negative)
1468 res
= (((sig_n_prime
.w
[1] > 0)
1469 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
1475 #if DECIMAL_CALL_BY_REFERENCE
1477 bid64_quiet_not_less (int *pres
, UINT64
* px
,
1479 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1485 bid64_quiet_not_less (UINT64 x
,
1486 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1491 UINT64 sig_x
, sig_y
;
1492 UINT128 sig_n_prime
;
1493 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1496 // if either number is NAN, the comparison is unordered : return 1
1497 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1498 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1499 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1505 // if all the bits are the same, these numbers are equal.
1511 if ((x
& MASK_INF
) == MASK_INF
) {
1512 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1513 if ((x
& MASK_SIGN
) == MASK_SIGN
)
1514 // x is -inf, so it is less than y unless y is -inf
1516 res
= (((y
& MASK_INF
) == MASK_INF
)
1517 && (y
& MASK_SIGN
) == MASK_SIGN
);
1520 // x is pos_inf, no way for it to be less than y
1525 } else if ((y
& MASK_INF
) == MASK_INF
) {
1527 // if y is +inf, x<y
1528 // if y is -inf, x>y
1530 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1534 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1535 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1536 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1537 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1538 if (sig_x
> 9999999999999999ull) {
1544 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1545 sig_x
= (x
& MASK_BINARY_SIG1
);
1549 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1550 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1551 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1552 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1553 if (sig_y
> 9999999999999999ull) {
1559 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1560 sig_y
= (y
& MASK_BINARY_SIG1
);
1566 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1567 // number is greater
1568 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1569 // therefore ignore the exponent field
1570 // (Any non-canonical # is considered 0)
1571 if (non_canon_x
|| sig_x
== 0) {
1574 if (non_canon_y
|| sig_y
== 0) {
1577 // if both numbers are zero, they are equal
1578 if (x_is_zero
&& y_is_zero
) {
1582 // if x is zero, it is lessthan if Y is positive
1583 else if (x_is_zero
) {
1584 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1587 // if y is zero, X is less if it is negative
1588 else if (y_is_zero
) {
1589 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1592 // OPPOSITE SIGN (CASE5)
1593 // now, if the sign bits differ, x is less than if y is positive
1594 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1595 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1598 // REDUNDANT REPRESENTATIONS (CASE6)
1599 // if both components are either bigger or smaller
1600 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1601 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1604 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1605 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1608 // if exp_x is 15 greater than exp_y, no need for compensation
1609 if (exp_x
- exp_y
> 15) {
1610 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1613 // difference cannot be greater than 10^15
1615 // if exp_x is 15 less than exp_y, no need for compensation
1616 if (exp_y
- exp_x
> 15) {
1617 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1620 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1621 if (exp_x
> exp_y
) { // to simplify the loop below,
1623 // otherwise adjust the x significand upwards
1624 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1625 mult_factor
[exp_x
- exp_y
]);
1627 // return 0 if values are equal
1628 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1632 // if postitive, return whichever significand abs is smaller
1633 // (converse if negative)
1635 res
= (((sig_n_prime
.w
[1] == 0)
1636 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
1641 // adjust the y significand upwards
1642 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1643 mult_factor
[exp_y
- exp_x
]);
1645 // return 0 if values are equal
1646 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1650 // if positive, return whichever significand abs is smaller
1651 // (converse if negative)
1653 res
= (((sig_n_prime
.w
[1] > 0)
1654 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=
1660 #if DECIMAL_CALL_BY_REFERENCE
1662 bid64_quiet_ordered (int *pres
, UINT64
* px
,
1664 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1670 bid64_quiet_ordered (UINT64 x
,
1671 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1677 // if either number is NAN, the comparison is ordered, rather than equal : return 0
1678 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1679 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1680 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1690 #if DECIMAL_CALL_BY_REFERENCE
1692 bid64_quiet_unordered (int *pres
, UINT64
* px
,
1694 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1700 bid64_quiet_unordered (UINT64 x
,
1701 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1707 // if either number is NAN, the comparison is unordered,
1708 // rather than equal : return 0
1709 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1710 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1711 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1721 #if DECIMAL_CALL_BY_REFERENCE
1723 bid64_signaling_greater (int *pres
, UINT64
* px
,
1725 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1731 bid64_signaling_greater (UINT64 x
,
1732 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1737 UINT64 sig_x
, sig_y
;
1738 UINT128 sig_n_prime
;
1739 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1742 // if either number is NAN, the comparison is unordered,
1743 // rather than equal : return 0
1744 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1745 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
1750 // if all the bits are the same, these numbers are equal (not Greater).
1756 if ((x
& MASK_INF
) == MASK_INF
) {
1757 // if x is neg infinity, there is no way it is greater than y, return 0
1758 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
1762 // x is pos infinity, it is greater,
1763 // unless y is positive infinity => return y!=pos_infinity
1765 res
= (((y
& MASK_INF
) != MASK_INF
)
1766 || ((y
& MASK_SIGN
) == MASK_SIGN
));
1769 } else if ((y
& MASK_INF
) == MASK_INF
) {
1770 // x is finite, so if y is positive infinity, then x is less, return 0
1771 // if y is negative infinity, then x is greater, return 1
1773 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1777 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1778 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1779 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1780 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1781 if (sig_x
> 9999999999999999ull) {
1787 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1788 sig_x
= (x
& MASK_BINARY_SIG1
);
1792 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1793 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1794 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1795 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1796 if (sig_y
> 9999999999999999ull) {
1802 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1803 sig_y
= (y
& MASK_BINARY_SIG1
);
1809 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1810 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1811 // therefore ignore the exponent field
1812 // (Any non-canonical # is considered 0)
1813 if (non_canon_x
|| sig_x
== 0) {
1816 if (non_canon_y
|| sig_y
== 0) {
1819 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
1820 if (x_is_zero
&& y_is_zero
) {
1824 // is x is zero, it is greater if Y is negative
1825 else if (x_is_zero
) {
1826 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1829 // is y is zero, X is greater if it is positive
1830 else if (y_is_zero
) {
1831 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1834 // OPPOSITE SIGN (CASE5)
1835 // now, if the sign bits differ, x is greater if y is negative
1836 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1837 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1840 // REDUNDANT REPRESENTATIONS (CASE6)
1842 // if both components are either bigger or smaller
1843 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1844 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1847 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1848 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1851 // if exp_x is 15 greater than exp_y, no need for compensation
1852 if (exp_x
- exp_y
> 15) {
1853 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1856 // difference cannot be greater than 10^15
1858 // if exp_x is 15 less than exp_y, no need for compensation
1859 if (exp_y
- exp_x
> 15) {
1860 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1863 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1864 if (exp_x
> exp_y
) { // to simplify the loop below,
1866 // otherwise adjust the x significand upwards
1867 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1868 mult_factor
[exp_x
- exp_y
]);
1871 // if postitive, return whichever significand is larger
1872 // (converse if negative)
1873 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1879 res
= (((sig_n_prime
.w
[1] > 0)
1880 || sig_n_prime
.w
[0] > sig_y
) ^ ((x
& MASK_SIGN
) ==
1885 // adjust the y significand upwards
1886 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1887 mult_factor
[exp_y
- exp_x
]);
1889 // if postitive, return whichever significand is larger
1890 // (converse if negative)
1891 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1896 res
= (((sig_n_prime
.w
[1] == 0)
1897 && (sig_x
> sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
1903 #if DECIMAL_CALL_BY_REFERENCE
1905 bid64_signaling_greater_equal (int *pres
, UINT64
* px
,
1907 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1913 bid64_signaling_greater_equal (UINT64 x
,
1914 UINT64 y _EXC_FLAGS_PARAM
1915 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
1919 UINT64 sig_x
, sig_y
;
1920 UINT128 sig_n_prime
;
1921 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1924 // if either number is NAN, the comparison is unordered : return 1
1925 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1926 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
1931 // if all the bits are the same, these numbers are equal.
1937 if ((x
& MASK_INF
) == MASK_INF
) {
1938 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1939 if ((x
& MASK_SIGN
) == MASK_SIGN
)
1940 // x is -inf, so it is less than y unless y is -inf
1942 res
= (((y
& MASK_INF
) == MASK_INF
)
1943 && (y
& MASK_SIGN
) == MASK_SIGN
);
1946 // x is pos_inf, no way for it to be less than y
1951 } else if ((y
& MASK_INF
) == MASK_INF
) {
1953 // if y is +inf, x<y
1954 // if y is -inf, x>y
1956 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1960 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1961 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1962 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1963 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1964 if (sig_x
> 9999999999999999ull) {
1970 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1971 sig_x
= (x
& MASK_BINARY_SIG1
);
1975 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1976 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1977 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1978 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1979 if (sig_y
> 9999999999999999ull) {
1985 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1986 sig_y
= (y
& MASK_BINARY_SIG1
);
1992 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1993 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1994 // therefore ignore the exponent field
1995 // (Any non-canonical # is considered 0)
1996 if (non_canon_x
|| sig_x
== 0) {
1999 if (non_canon_y
|| sig_y
== 0) {
2002 // if both numbers are zero, they are equal
2003 if (x_is_zero
&& y_is_zero
) {
2007 // if x is zero, it is lessthan if Y is positive
2008 else if (x_is_zero
) {
2009 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2012 // if y is zero, X is less if it is negative
2013 else if (y_is_zero
) {
2014 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2017 // OPPOSITE SIGN (CASE5)
2018 // now, if the sign bits differ, x is less than if y is positive
2019 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2020 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2023 // REDUNDANT REPRESENTATIONS (CASE6)
2024 // if both components are either bigger or smaller
2025 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2026 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2029 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2030 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2033 // if exp_x is 15 greater than exp_y, no need for compensation
2034 if (exp_x
- exp_y
> 15) {
2035 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2038 // difference cannot be greater than 10^15
2040 // if exp_x is 15 less than exp_y, no need for compensation
2041 if (exp_y
- exp_x
> 15) {
2042 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2045 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2046 if (exp_x
> exp_y
) { // to simplify the loop below,
2048 // otherwise adjust the x significand upwards
2049 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2050 mult_factor
[exp_x
- exp_y
]);
2052 // return 1 if values are equal
2053 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2057 // if postitive, return whichever significand abs is smaller
2058 // (converse if negative)
2060 res
= (((sig_n_prime
.w
[1] == 0)
2061 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
2066 // adjust the y significand upwards
2067 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2068 mult_factor
[exp_y
- exp_x
]);
2070 // return 0 if values are equal
2071 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2075 // if positive, return whichever significand abs is smaller
2076 // (converse if negative)
2078 res
= (((sig_n_prime
.w
[1] > 0)
2079 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=
2085 #if DECIMAL_CALL_BY_REFERENCE
2087 bid64_signaling_greater_unordered (int *pres
, UINT64
* px
,
2089 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2095 bid64_signaling_greater_unordered (UINT64 x
,
2096 UINT64 y _EXC_FLAGS_PARAM
2097 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
2101 UINT64 sig_x
, sig_y
;
2102 UINT128 sig_n_prime
;
2103 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2106 // if either number is NAN, the comparison is unordered,
2107 // rather than equal : return 0
2108 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2109 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2114 // if all the bits are the same, these numbers are equal (not Greater).
2120 if ((x
& MASK_INF
) == MASK_INF
) {
2121 // if x is neg infinity, there is no way it is greater than y, return 0
2122 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
2126 // x is pos infinity, it is greater,
2127 // unless y is positive infinity => return y!=pos_infinity
2129 res
= (((y
& MASK_INF
) != MASK_INF
)
2130 || ((y
& MASK_SIGN
) == MASK_SIGN
));
2133 } else if ((y
& MASK_INF
) == MASK_INF
) {
2134 // x is finite, so if y is positive infinity, then x is less, return 0
2135 // if y is negative infinity, then x is greater, return 1
2137 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2141 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2142 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2143 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2144 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2145 if (sig_x
> 9999999999999999ull) {
2151 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2152 sig_x
= (x
& MASK_BINARY_SIG1
);
2156 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2157 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2158 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2159 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2160 if (sig_y
> 9999999999999999ull) {
2166 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2167 sig_y
= (y
& MASK_BINARY_SIG1
);
2173 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2174 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2175 // therefore ignore the exponent field
2176 // (Any non-canonical # is considered 0)
2177 if (non_canon_x
|| sig_x
== 0) {
2180 if (non_canon_y
|| sig_y
== 0) {
2183 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
2184 if (x_is_zero
&& y_is_zero
) {
2188 // is x is zero, it is greater if Y is negative
2189 else if (x_is_zero
) {
2190 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2193 // is y is zero, X is greater if it is positive
2194 else if (y_is_zero
) {
2195 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2198 // OPPOSITE SIGN (CASE5)
2199 // now, if the sign bits differ, x is greater if y is negative
2200 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2201 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2204 // REDUNDANT REPRESENTATIONS (CASE6)
2206 // if both components are either bigger or smaller
2207 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2208 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2211 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2212 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2215 // if exp_x is 15 greater than exp_y, no need for compensation
2216 if (exp_x
- exp_y
> 15) {
2217 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2220 // difference cannot be greater than 10^15
2222 // if exp_x is 15 less than exp_y, no need for compensation
2223 if (exp_y
- exp_x
> 15) {
2224 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2227 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2228 if (exp_x
> exp_y
) { // to simplify the loop below,
2230 // otherwise adjust the x significand upwards
2231 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2232 mult_factor
[exp_x
- exp_y
]);
2234 // if postitive, return whichever significand is larger
2235 // (converse if negative)
2236 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2242 res
= (((sig_n_prime
.w
[1] > 0)
2243 || sig_n_prime
.w
[0] > sig_y
) ^ ((x
& MASK_SIGN
) ==
2248 // adjust the y significand upwards
2249 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2250 mult_factor
[exp_y
- exp_x
]);
2252 // if postitive, return whichever significand is larger
2253 // (converse if negative)
2254 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2259 res
= (((sig_n_prime
.w
[1] == 0)
2260 && (sig_x
> sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2266 #if DECIMAL_CALL_BY_REFERENCE
2268 bid64_signaling_less (int *pres
, UINT64
* px
,
2270 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2276 bid64_signaling_less (UINT64 x
,
2277 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2282 UINT64 sig_x
, sig_y
;
2283 UINT128 sig_n_prime
;
2284 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2287 // if either number is NAN, the comparison is unordered : return 0
2288 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2289 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2294 // if all the bits are the same, these numbers are equal.
2300 if ((x
& MASK_INF
) == MASK_INF
) {
2301 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2302 if ((x
& MASK_SIGN
) == MASK_SIGN
)
2303 // x is -inf, so it is less than y unless y is -inf
2305 res
= (((y
& MASK_INF
) != MASK_INF
)
2306 || (y
& MASK_SIGN
) != MASK_SIGN
);
2309 // x is pos_inf, no way for it to be less than y
2314 } else if ((y
& MASK_INF
) == MASK_INF
) {
2316 // if y is +inf, x<y
2317 // if y is -inf, x>y
2319 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2323 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2324 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2325 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2326 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2327 if (sig_x
> 9999999999999999ull) {
2333 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2334 sig_x
= (x
& MASK_BINARY_SIG1
);
2338 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2339 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2340 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2341 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2342 if (sig_y
> 9999999999999999ull) {
2348 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2349 sig_y
= (y
& MASK_BINARY_SIG1
);
2355 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2356 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2357 // therefore ignore the exponent field
2358 // (Any non-canonical # is considered 0)
2359 if (non_canon_x
|| sig_x
== 0) {
2362 if (non_canon_y
|| sig_y
== 0) {
2365 // if both numbers are zero, they are equal
2366 if (x_is_zero
&& y_is_zero
) {
2370 // if x is zero, it is lessthan if Y is positive
2371 else if (x_is_zero
) {
2372 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2375 // if y is zero, X is less if it is negative
2376 else if (y_is_zero
) {
2377 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2380 // OPPOSITE SIGN (CASE5)
2381 // now, if the sign bits differ, x is less than if y is positive
2382 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2383 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2386 // REDUNDANT REPRESENTATIONS (CASE6)
2387 // if both components are either bigger or smaller
2388 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2389 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2392 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2393 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2396 // if exp_x is 15 greater than exp_y, no need for compensation
2397 if (exp_x
- exp_y
> 15) {
2398 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2401 // difference cannot be greater than 10^15
2403 // if exp_x is 15 less than exp_y, no need for compensation
2404 if (exp_y
- exp_x
> 15) {
2405 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2408 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2409 if (exp_x
> exp_y
) { // to simplify the loop below,
2411 // otherwise adjust the x significand upwards
2412 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2413 mult_factor
[exp_x
- exp_y
]);
2415 // return 0 if values are equal
2416 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2420 // if postitive, return whichever significand abs is smaller
2421 // (converse if negative)
2423 res
= (((sig_n_prime
.w
[1] == 0)
2424 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2429 // adjust the y significand upwards
2430 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2431 mult_factor
[exp_y
- exp_x
]);
2433 // return 0 if values are equal
2434 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2438 // if positive, return whichever significand abs is smaller
2439 // (converse if negative)
2441 res
= (((sig_n_prime
.w
[1] > 0)
2442 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2448 #if DECIMAL_CALL_BY_REFERENCE
2450 bid64_signaling_less_equal (int *pres
, UINT64
* px
,
2452 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2458 bid64_signaling_less_equal (UINT64 x
,
2459 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2464 UINT64 sig_x
, sig_y
;
2465 UINT128 sig_n_prime
;
2466 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2469 // if either number is NAN, the comparison is unordered,
2470 // rather than equal : return 0
2471 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2472 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2477 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2483 if ((x
& MASK_INF
) == MASK_INF
) {
2484 // if x is neg infinity, it must be lessthan or equal to y return 1
2485 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
2489 // x is pos infinity, it is greater,
2490 // unless y is positive infinity => return y==pos_infinity
2492 res
= !(((y
& MASK_INF
) != MASK_INF
)
2493 || ((y
& MASK_SIGN
) == MASK_SIGN
));
2496 } else if ((y
& MASK_INF
) == MASK_INF
) {
2497 // x is finite, so if y is positive infinity, then x is less, return 1
2498 // if y is negative infinity, then x is greater, return 0
2500 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2504 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2505 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2506 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2507 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2508 if (sig_x
> 9999999999999999ull) {
2514 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2515 sig_x
= (x
& MASK_BINARY_SIG1
);
2519 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2520 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2521 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2522 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2523 if (sig_y
> 9999999999999999ull) {
2529 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2530 sig_y
= (y
& MASK_BINARY_SIG1
);
2536 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2537 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2538 // therefore ignore the exponent field
2539 // (Any non-canonical # is considered 0)
2540 if (non_canon_x
|| sig_x
== 0) {
2543 if (non_canon_y
|| sig_y
== 0) {
2546 // if both numbers are zero, they are equal -> return 1
2547 if (x_is_zero
&& y_is_zero
) {
2551 // if x is zero, it is lessthan if Y is positive
2552 else if (x_is_zero
) {
2553 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2556 // if y is zero, X is less if it is negative
2557 else if (y_is_zero
) {
2558 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2561 // OPPOSITE SIGN (CASE5)
2562 // now, if the sign bits differ, x is less than if y is positive
2563 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2564 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2567 // REDUNDANT REPRESENTATIONS (CASE6)
2568 // if both components are either bigger or smaller
2569 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2570 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2573 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2574 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2577 // if exp_x is 15 greater than exp_y, no need for compensation
2578 if (exp_x
- exp_y
> 15) {
2579 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2582 // difference cannot be greater than 10^15
2584 // if exp_x is 15 less than exp_y, no need for compensation
2585 if (exp_y
- exp_x
> 15) {
2586 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2589 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2590 if (exp_x
> exp_y
) { // to simplify the loop below,
2592 // otherwise adjust the x significand upwards
2593 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2594 mult_factor
[exp_x
- exp_y
]);
2596 // return 1 if values are equal
2597 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2601 // if postitive, return whichever significand abs is smaller
2602 // (converse if negative)
2604 res
= (((sig_n_prime
.w
[1] == 0)
2605 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2610 // adjust the y significand upwards
2611 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2612 mult_factor
[exp_y
- exp_x
]);
2614 // return 1 if values are equal
2615 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2619 // if positive, return whichever significand abs is smaller
2620 // (converse if negative)
2622 res
= (((sig_n_prime
.w
[1] > 0)
2623 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2629 #if DECIMAL_CALL_BY_REFERENCE
2631 bid64_signaling_less_unordered (int *pres
, UINT64
* px
,
2633 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2639 bid64_signaling_less_unordered (UINT64 x
,
2640 UINT64 y _EXC_FLAGS_PARAM
2641 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
2645 UINT64 sig_x
, sig_y
;
2646 UINT128 sig_n_prime
;
2647 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2650 // if either number is NAN, the comparison is unordered : return 0
2651 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2652 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2657 // if all the bits are the same, these numbers are equal.
2663 if ((x
& MASK_INF
) == MASK_INF
) {
2664 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2665 if ((x
& MASK_SIGN
) == MASK_SIGN
)
2666 // x is -inf, so it is less than y unless y is -inf
2668 res
= (((y
& MASK_INF
) != MASK_INF
)
2669 || (y
& MASK_SIGN
) != MASK_SIGN
);
2672 // x is pos_inf, no way for it to be less than y
2677 } else if ((y
& MASK_INF
) == MASK_INF
) {
2679 // if y is +inf, x<y
2680 // if y is -inf, x>y
2682 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2686 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2687 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2688 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2689 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2690 if (sig_x
> 9999999999999999ull) {
2696 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2697 sig_x
= (x
& MASK_BINARY_SIG1
);
2701 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2702 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2703 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2704 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2705 if (sig_y
> 9999999999999999ull) {
2711 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2712 sig_y
= (y
& MASK_BINARY_SIG1
);
2718 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2719 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2720 // therefore ignore the exponent field
2721 // (Any non-canonical # is considered 0)
2722 if (non_canon_x
|| sig_x
== 0) {
2725 if (non_canon_y
|| sig_y
== 0) {
2728 // if both numbers are zero, they are equal
2729 if (x_is_zero
&& y_is_zero
) {
2733 // if x is zero, it is lessthan if Y is positive
2734 else if (x_is_zero
) {
2735 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2738 // if y is zero, X is less if it is negative
2739 else if (y_is_zero
) {
2740 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2743 // OPPOSITE SIGN (CASE5)
2744 // now, if the sign bits differ, x is less than if y is positive
2745 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2746 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2749 // REDUNDANT REPRESENTATIONS (CASE6)
2750 // if both components are either bigger or smaller
2751 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2752 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2755 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2756 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2759 // if exp_x is 15 greater than exp_y, no need for compensation
2760 if (exp_x
- exp_y
> 15) {
2761 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2764 // difference cannot be greater than 10^15
2766 // if exp_x is 15 less than exp_y, no need for compensation
2767 if (exp_y
- exp_x
> 15) {
2768 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2771 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2772 if (exp_x
> exp_y
) { // to simplify the loop below,
2774 // otherwise adjust the x significand upwards
2775 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2776 mult_factor
[exp_x
- exp_y
]);
2778 // return 0 if values are equal
2779 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2783 // if postitive, return whichever significand abs is smaller
2784 // (converse if negative)
2786 res
= (((sig_n_prime
.w
[1] == 0)
2787 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2792 // adjust the y significand upwards
2793 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2794 mult_factor
[exp_y
- exp_x
]);
2796 // return 0 if values are equal
2797 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2801 // if positive, return whichever significand abs is smaller
2802 // (converse if negative)
2804 res
= (((sig_n_prime
.w
[1] > 0)
2805 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2811 #if DECIMAL_CALL_BY_REFERENCE
2813 bid64_signaling_not_greater (int *pres
, UINT64
* px
,
2815 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2821 bid64_signaling_not_greater (UINT64 x
,
2822 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2827 UINT64 sig_x
, sig_y
;
2828 UINT128 sig_n_prime
;
2829 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2832 // if either number is NAN, the comparison is unordered,
2833 // rather than equal : return 0
2834 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2835 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2840 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2846 if ((x
& MASK_INF
) == MASK_INF
) {
2847 // if x is neg infinity, it must be lessthan or equal to y return 1
2848 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
2852 // x is pos infinity, it is greater,
2853 // unless y is positive infinity => return y==pos_infinity
2855 res
= !(((y
& MASK_INF
) != MASK_INF
)
2856 || ((y
& MASK_SIGN
) == MASK_SIGN
));
2859 } else if ((y
& MASK_INF
) == MASK_INF
) {
2860 // x is finite, so if y is positive infinity, then x is less, return 1
2861 // if y is negative infinity, then x is greater, return 0
2863 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2867 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2868 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2869 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2870 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2871 if (sig_x
> 9999999999999999ull) {
2877 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2878 sig_x
= (x
& MASK_BINARY_SIG1
);
2882 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2883 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2884 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2885 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2886 if (sig_y
> 9999999999999999ull) {
2892 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2893 sig_y
= (y
& MASK_BINARY_SIG1
);
2899 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2900 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2901 // therefore ignore the exponent field
2902 // (Any non-canonical # is considered 0)
2903 if (non_canon_x
|| sig_x
== 0) {
2906 if (non_canon_y
|| sig_y
== 0) {
2909 // if both numbers are zero, they are equal -> return 1
2910 if (x_is_zero
&& y_is_zero
) {
2914 // if x is zero, it is lessthan if Y is positive
2915 else if (x_is_zero
) {
2916 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2919 // if y is zero, X is less if it is negative
2920 else if (y_is_zero
) {
2921 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2924 // OPPOSITE SIGN (CASE5)
2925 // now, if the sign bits differ, x is less than if y is positive
2926 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2927 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2930 // REDUNDANT REPRESENTATIONS (CASE6)
2931 // if both components are either bigger or smaller
2932 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2933 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2936 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2937 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2940 // if exp_x is 15 greater than exp_y, no need for compensation
2941 if (exp_x
- exp_y
> 15) {
2942 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2945 // difference cannot be greater than 10^15
2947 // if exp_x is 15 less than exp_y, no need for compensation
2948 if (exp_y
- exp_x
> 15) {
2949 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2952 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2953 if (exp_x
> exp_y
) { // to simplify the loop below,
2955 // otherwise adjust the x significand upwards
2956 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2957 mult_factor
[exp_x
- exp_y
]);
2959 // return 1 if values are equal
2960 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2964 // if postitive, return whichever significand abs is smaller
2965 // (converse if negative)
2967 res
= (((sig_n_prime
.w
[1] == 0)
2968 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2973 // adjust the y significand upwards
2974 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2975 mult_factor
[exp_y
- exp_x
]);
2977 // return 1 if values are equal
2978 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2982 // if positive, return whichever significand abs is smaller
2983 // (converse if negative)
2985 res
= (((sig_n_prime
.w
[1] > 0)
2986 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2992 #if DECIMAL_CALL_BY_REFERENCE
2994 bid64_signaling_not_less (int *pres
, UINT64
* px
,
2996 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3002 bid64_signaling_not_less (UINT64 x
,
3003 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3008 UINT64 sig_x
, sig_y
;
3009 UINT128 sig_n_prime
;
3010 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
3013 // if either number is NAN, the comparison is unordered : return 1
3014 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
3015 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
3020 // if all the bits are the same, these numbers are equal.
3026 if ((x
& MASK_INF
) == MASK_INF
) {
3027 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
3028 if ((x
& MASK_SIGN
) == MASK_SIGN
)
3029 // x is -inf, so it is less than y unless y is -inf
3031 res
= (((y
& MASK_INF
) == MASK_INF
)
3032 && (y
& MASK_SIGN
) == MASK_SIGN
);
3035 // x is pos_inf, no way for it to be less than y
3040 } else if ((y
& MASK_INF
) == MASK_INF
) {
3042 // if y is +inf, x<y
3043 // if y is -inf, x>y
3045 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
3049 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3050 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
3051 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
3052 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
3053 if (sig_x
> 9999999999999999ull) {
3059 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
3060 sig_x
= (x
& MASK_BINARY_SIG1
);
3064 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3065 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
3066 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
3067 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
3068 if (sig_y
> 9999999999999999ull) {
3074 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
3075 sig_y
= (y
& MASK_BINARY_SIG1
);
3081 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
3082 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
3083 // therefore ignore the exponent field
3084 // (Any non-canonical # is considered 0)
3085 if (non_canon_x
|| sig_x
== 0) {
3088 if (non_canon_y
|| sig_y
== 0) {
3091 // if both numbers are zero, they are equal
3092 if (x_is_zero
&& y_is_zero
) {
3096 // if x is zero, it is lessthan if Y is positive
3097 else if (x_is_zero
) {
3098 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
3101 // if y is zero, X is less if it is negative
3102 else if (y_is_zero
) {
3103 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
3106 // OPPOSITE SIGN (CASE5)
3107 // now, if the sign bits differ, x is less than if y is positive
3108 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
3109 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
3112 // REDUNDANT REPRESENTATIONS (CASE6)
3113 // if both components are either bigger or smaller
3114 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
3115 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
3118 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
3119 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
3122 // if exp_x is 15 greater than exp_y, no need for compensation
3123 if (exp_x
- exp_y
> 15) {
3124 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
3127 // difference cannot be greater than 10^15
3129 // if exp_x is 15 less than exp_y, no need for compensation
3130 if (exp_y
- exp_x
> 15) {
3131 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
3134 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
3135 if (exp_x
> exp_y
) { // to simplify the loop below,
3137 // otherwise adjust the x significand upwards
3138 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
3139 mult_factor
[exp_x
- exp_y
]);
3141 // return 0 if values are equal
3142 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
3146 // if postitive, return whichever significand abs is smaller
3147 // (converse if negative)
3149 res
= (((sig_n_prime
.w
[1] == 0)
3150 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
3155 // adjust the y significand upwards
3156 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
3157 mult_factor
[exp_y
- exp_x
]);
3159 // return 0 if values are equal
3160 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
3164 // if positive, return whichever significand abs is smaller
3165 // (converse if negative)
3167 res
= (((sig_n_prime
.w
[1] > 0)
3168 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=