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 // ONE INFINITY (CASE3')
80 if (((x
& MASK_INF
) == MASK_INF
) || ((y
& MASK_INF
) == MASK_INF
)) {
84 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
85 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
86 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
87 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
88 if (sig_x
> 9999999999999999ull) {
94 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
95 sig_x
= (x
& MASK_BINARY_SIG1
);
98 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
99 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
100 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
101 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
102 if (sig_y
> 9999999999999999ull) {
108 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
109 sig_y
= (y
& MASK_BINARY_SIG1
);
114 // (+ZERO==-ZERO) => therefore ignore the sign
115 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
116 // therefore ignore the exponent field
117 // (Any non-canonical # is considered 0)
118 if (non_canon_x
|| sig_x
== 0) {
121 if (non_canon_y
|| sig_y
== 0) {
124 if (x_is_zero
&& y_is_zero
) {
127 } else if ((x_is_zero
&& !y_is_zero
) || (!x_is_zero
&& y_is_zero
)) {
131 // OPPOSITE SIGN (CASE5)
132 // now, if the sign bits differ => not equal : return 0
133 if ((x
^ y
) & MASK_SIGN
) {
137 // REDUNDANT REPRESENTATIONS (CASE6)
138 if (exp_x
> exp_y
) { // to simplify the loop below,
139 SWAP (exp_x
, exp_y
, exp_t
); // put the larger exp in y,
140 SWAP (sig_x
, sig_y
, sig_t
); // and the smaller exp in x
142 if (exp_y
- exp_x
> 15) {
143 res
= 0; // difference cannot be greater than 10^15
146 for (lcv
= 0; lcv
< (exp_y
- exp_x
); lcv
++) {
147 // recalculate y's significand upwards
149 if (sig_y
> 9999999999999999ull) {
154 res
= (sig_y
== sig_x
);
158 #if DECIMAL_CALL_BY_REFERENCE
160 bid64_quiet_greater (int *pres
, UINT64
* px
,
162 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
168 bid64_quiet_greater (UINT64 x
,
169 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
176 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
179 // if either number is NAN, the comparison is unordered, rather than equal :
181 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
182 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
183 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
189 // if all the bits are the same, these numbers are equal (not Greater).
195 if ((x
& MASK_INF
) == MASK_INF
) {
196 // if x is neg infinity, there is no way it is greater than y, return 0
197 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
201 // x is pos infinity, it is greater, unless y is positive
202 // infinity => return y!=pos_infinity
203 res
= (((y
& MASK_INF
) != MASK_INF
)
204 || ((y
& MASK_SIGN
) == MASK_SIGN
));
207 } else if ((y
& MASK_INF
) == MASK_INF
) {
208 // x is finite, so if y is positive infinity, then x is less, return 0
209 // if y is negative infinity, then x is greater, return 1
210 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
213 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
214 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
215 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
216 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
217 if (sig_x
> 9999999999999999ull) {
223 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
224 sig_x
= (x
& MASK_BINARY_SIG1
);
227 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
228 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
229 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
230 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
231 if (sig_y
> 9999999999999999ull) {
237 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
238 sig_y
= (y
& MASK_BINARY_SIG1
);
243 //(+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
244 //(ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore ignore the
246 // (Any non-canonical # is considered 0)
247 if (non_canon_x
|| sig_x
== 0) {
250 if (non_canon_y
|| sig_y
== 0) {
253 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
254 if (x_is_zero
&& y_is_zero
) {
257 } else if (x_is_zero
) {
258 // is x is zero, it is greater if Y is negative
259 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
261 } else if (y_is_zero
) {
262 // is y is zero, X is greater if it is positive
263 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
266 // OPPOSITE SIGN (CASE5)
267 // now, if the sign bits differ, x is greater if y is negative
268 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
269 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
272 // REDUNDANT REPRESENTATIONS (CASE6)
273 // if both components are either bigger or smaller,
274 // it is clear what needs to be done
275 if (sig_x
> sig_y
&& exp_x
> exp_y
) {
276 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
279 if (sig_x
< sig_y
&& exp_x
< exp_y
) {
280 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
283 // if exp_x is 15 greater than exp_y, no need for compensation
284 if (exp_x
- exp_y
> 15) { // difference cannot be greater than 10^15
285 if (x
& MASK_SIGN
) // if both are negative
287 else // if both are positive
291 // if exp_x is 15 less than exp_y, no need for compensation
292 if (exp_y
- exp_x
> 15) {
293 if (x
& MASK_SIGN
) // if both are negative
295 else // if both are positive
299 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
300 if (exp_x
> exp_y
) { // to simplify the loop below,
301 // otherwise adjust the x significand upwards
302 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
303 mult_factor
[exp_x
- exp_y
]);
304 // if postitive, return whichever significand is larger (converse if neg.)
305 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
309 res
= (((sig_n_prime
.w
[1] > 0)
310 || sig_n_prime
.w
[0] > sig_y
) ^ ((x
& MASK_SIGN
) ==
314 // adjust the y significand upwards
315 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
316 mult_factor
[exp_y
- exp_x
]);
317 // if postitive, return whichever significand is larger
318 // (converse if negative)
319 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
323 res
= (((sig_n_prime
.w
[1] == 0)
324 && (sig_x
> sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
329 #if DECIMAL_CALL_BY_REFERENCE
331 bid64_quiet_greater_equal (int *pres
, UINT64
* px
,
333 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
339 bid64_quiet_greater_equal (UINT64 x
,
340 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
347 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
350 // if either number is NAN, the comparison is unordered : return 1
351 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
352 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
353 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
359 // if all the bits are the same, these numbers are equal.
365 if ((x
& MASK_INF
) == MASK_INF
) {
366 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
367 if ((x
& MASK_SIGN
) == MASK_SIGN
) {
368 // x is -inf, so it is less than y unless y is -inf
369 res
= (((y
& MASK_INF
) == MASK_INF
)
370 && (y
& MASK_SIGN
) == MASK_SIGN
);
372 } else { // x is pos_inf, no way for it to be less than y
376 } else if ((y
& MASK_INF
) == MASK_INF
) {
380 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
383 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
384 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
385 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
386 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
387 if (sig_x
> 9999999999999999ull) {
393 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
394 sig_x
= (x
& MASK_BINARY_SIG1
);
397 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
398 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
399 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
400 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
401 if (sig_y
> 9999999999999999ull) {
407 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
408 sig_y
= (y
& MASK_BINARY_SIG1
);
413 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
414 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
415 // therefore ignore the exponent field
416 // (Any non-canonical # is considered 0)
417 if (non_canon_x
|| sig_x
== 0) {
420 if (non_canon_y
|| sig_y
== 0) {
423 if (x_is_zero
&& y_is_zero
) {
424 // if both numbers are zero, they are equal
427 } else if (x_is_zero
) {
428 // if x is zero, it is lessthan if Y is positive
429 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
431 } else if (y_is_zero
) {
432 // if y is zero, X is less if it is negative
433 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
436 // OPPOSITE SIGN (CASE5)
437 // now, if the sign bits differ, x is less than if y is positive
438 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
439 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
442 // REDUNDANT REPRESENTATIONS (CASE6)
443 // if both components are either bigger or smaller
444 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
445 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
448 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
449 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
452 // if exp_x is 15 greater than exp_y, no need for compensation
453 if (exp_x
- exp_y
> 15) {
454 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
455 // difference cannot be greater than 10^15
458 // if exp_x is 15 less than exp_y, no need for compensation
459 if (exp_y
- exp_x
> 15) {
460 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
463 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
464 if (exp_x
> exp_y
) { // to simplify the loop below,
465 // otherwise adjust the x significand upwards
466 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
467 mult_factor
[exp_x
- exp_y
]);
468 // return 1 if values are equal
469 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
473 // if postitive, return whichever significand abs is smaller
474 // (converse if negative)
475 res
= (((sig_n_prime
.w
[1] == 0)
476 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
480 // adjust the y significand upwards
481 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
482 mult_factor
[exp_y
- exp_x
]);
483 // return 0 if values are equal
484 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
488 // if positive, return whichever significand abs is smaller
489 // (converse if negative)
490 res
= (((sig_n_prime
.w
[1] > 0)
491 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=
496 #if DECIMAL_CALL_BY_REFERENCE
498 bid64_quiet_greater_unordered (int *pres
, UINT64
* px
,
500 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
506 bid64_quiet_greater_unordered (UINT64 x
,
507 UINT64 y _EXC_FLAGS_PARAM
508 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
514 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
517 // if either number is NAN, the comparison is unordered, rather than equal :
519 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
520 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
521 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
527 // if all the bits are the same, these numbers are equal (not Greater).
533 if ((x
& MASK_INF
) == MASK_INF
) {
534 // if x is neg infinity, there is no way it is greater than y, return 0
535 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
539 // x is pos infinity, it is greater, unless y is positive infinity =>
540 // return y!=pos_infinity
541 res
= (((y
& MASK_INF
) != MASK_INF
)
542 || ((y
& MASK_SIGN
) == MASK_SIGN
));
545 } else if ((y
& MASK_INF
) == MASK_INF
) {
546 // x is finite, so if y is positive infinity, then x is less, return 0
547 // if y is negative infinity, then x is greater, return 1
548 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
551 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
552 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
553 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
554 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
555 if (sig_x
> 9999999999999999ull) {
561 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
562 sig_x
= (x
& MASK_BINARY_SIG1
);
565 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
566 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
567 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
568 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
569 if (sig_y
> 9999999999999999ull) {
575 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
576 sig_y
= (y
& MASK_BINARY_SIG1
);
581 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
582 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
583 // therefore ignore the exponent field
584 // (Any non-canonical # is considered 0)
585 if (non_canon_x
|| sig_x
== 0) {
588 if (non_canon_y
|| sig_y
== 0) {
591 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
592 if (x_is_zero
&& y_is_zero
) {
595 } else if (x_is_zero
) {
596 // is x is zero, it is greater if Y is negative
597 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
599 } else if (y_is_zero
) {
600 // is y is zero, X is greater if it is positive
601 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
604 // OPPOSITE SIGN (CASE5)
605 // now, if the sign bits differ, x is greater if y is negative
606 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
607 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
610 // REDUNDANT REPRESENTATIONS (CASE6)
611 // if both components are either bigger or smaller
612 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
613 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
616 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
617 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
620 // if exp_x is 15 greater than exp_y, no need for compensation
621 if (exp_x
- exp_y
> 15) {
622 // difference cannot be greater than 10^15
623 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
626 // if exp_x is 15 less than exp_y, no need for compensation
627 if (exp_y
- exp_x
> 15) {
628 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
631 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
632 if (exp_x
> exp_y
) { // to simplify the loop below,
633 // otherwise adjust the x significand upwards
634 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
635 mult_factor
[exp_x
- exp_y
]);
636 // if postitive, return whichever significand is larger
637 // (converse if negative)
638 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
642 res
= (((sig_n_prime
.w
[1] > 0)
643 || sig_n_prime
.w
[0] > sig_y
) ^ ((x
& MASK_SIGN
) ==
647 // adjust the y significand upwards
648 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
649 mult_factor
[exp_y
- exp_x
]);
650 // if postitive, return whichever significand is larger (converse if negative)
651 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
655 res
= (((sig_n_prime
.w
[1] == 0)
656 && (sig_x
> sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
661 #if DECIMAL_CALL_BY_REFERENCE
663 bid64_quiet_less (int *pres
, UINT64
* px
,
665 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM
)
671 bid64_quiet_less (UINT64 x
,
672 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
679 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
682 // if either number is NAN, the comparison is unordered : return 0
683 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
684 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
685 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
691 // if all the bits are the same, these numbers are equal.
697 if ((x
& MASK_INF
) == MASK_INF
) {
698 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
699 if ((x
& MASK_SIGN
) == MASK_SIGN
) {
700 // x is -inf, so it is less than y unless y is -inf
701 res
= (((y
& MASK_INF
) != MASK_INF
)
702 || (y
& MASK_SIGN
) != MASK_SIGN
);
705 // x is pos_inf, no way for it to be less than y
709 } else if ((y
& MASK_INF
) == MASK_INF
) {
713 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
716 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
717 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
718 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
719 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
720 if (sig_x
> 9999999999999999ull) {
726 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
727 sig_x
= (x
& MASK_BINARY_SIG1
);
730 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
731 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
732 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
733 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
734 if (sig_y
> 9999999999999999ull) {
740 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
741 sig_y
= (y
& MASK_BINARY_SIG1
);
746 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
747 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
748 // therefore ignore the exponent field
749 // (Any non-canonical # is considered 0)
750 if (non_canon_x
|| sig_x
== 0) {
753 if (non_canon_y
|| sig_y
== 0) {
756 if (x_is_zero
&& y_is_zero
) {
757 // if both numbers are zero, they are equal
760 } else if (x_is_zero
) {
761 // if x is zero, it is lessthan if Y is positive
762 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
764 } else if (y_is_zero
) {
765 // if y is zero, X is less if it is negative
766 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
769 // OPPOSITE SIGN (CASE5)
770 // now, if the sign bits differ, x is less than if y is positive
771 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
772 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
775 // REDUNDANT REPRESENTATIONS (CASE6)
776 // if both components are either bigger or smaller,
777 // it is clear what needs to be done
778 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
779 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
782 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
783 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
786 // if exp_x is 15 greater than exp_y, no need for compensation
787 if (exp_x
- exp_y
> 15) {
788 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
789 // difference cannot be greater than 10^15
792 // if exp_x is 15 less than exp_y, no need for compensation
793 if (exp_y
- exp_x
> 15) {
794 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
797 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
798 if (exp_x
> exp_y
) { // to simplify the loop below,
799 // otherwise adjust the x significand upwards
800 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
801 mult_factor
[exp_x
- exp_y
]);
802 // return 0 if values are equal
803 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
807 // if postitive, return whichever significand abs is smaller
808 // (converse if negative)
809 res
= (((sig_n_prime
.w
[1] == 0)
810 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
814 // adjust the y significand upwards
815 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
816 mult_factor
[exp_y
- exp_x
]);
817 // return 0 if values are equal
818 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
822 // if positive, return whichever significand abs is smaller
823 // (converse if negative)
824 res
= (((sig_n_prime
.w
[1] > 0)
825 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
830 #if DECIMAL_CALL_BY_REFERENCE
832 bid64_quiet_less_equal (int *pres
, UINT64
* px
,
834 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
840 bid64_quiet_less_equal (UINT64 x
,
841 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
848 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
851 // if either number is NAN, the comparison is unordered, rather than equal :
853 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
854 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
855 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
861 // if all the bits are the same, these numbers are equal (LESSEQUAL).
867 if ((x
& MASK_INF
) == MASK_INF
) {
868 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
869 // if x is neg infinity, it must be lessthan or equal to y return 1
873 // x is pos infinity, it is greater, unless y is positive infinity =>
874 // return y==pos_infinity
875 res
= !(((y
& MASK_INF
) != MASK_INF
)
876 || ((y
& MASK_SIGN
) == MASK_SIGN
));
879 } else if ((y
& MASK_INF
) == MASK_INF
) {
880 // x is finite, so if y is positive infinity, then x is less, return 1
881 // if y is negative infinity, then x is greater, return 0
882 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
885 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
886 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
887 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
888 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
889 if (sig_x
> 9999999999999999ull) {
895 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
896 sig_x
= (x
& MASK_BINARY_SIG1
);
899 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
900 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
901 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
902 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
903 if (sig_y
> 9999999999999999ull) {
909 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
910 sig_y
= (y
& MASK_BINARY_SIG1
);
915 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
916 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
917 // therefore ignore the exponent field
918 // (Any non-canonical # is considered 0)
919 if (non_canon_x
|| sig_x
== 0) {
922 if (non_canon_y
|| sig_y
== 0) {
925 if (x_is_zero
&& y_is_zero
) {
926 // if both numbers are zero, they are equal -> return 1
929 } else if (x_is_zero
) {
930 // if x is zero, it is lessthan if Y is positive
931 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
933 } else if (y_is_zero
) {
934 // if y is zero, X is less if it is negative
935 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
938 // OPPOSITE SIGN (CASE5)
939 // now, if the sign bits differ, x is less than if y is positive
940 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
941 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
944 // REDUNDANT REPRESENTATIONS (CASE6)
945 // if both components are either bigger or smaller
946 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
947 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
950 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
951 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
954 // if exp_x is 15 greater than exp_y, no need for compensation
955 if (exp_x
- exp_y
> 15) {
956 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
957 // difference cannot be greater than 10^15
960 // if exp_x is 15 less than exp_y, no need for compensation
961 if (exp_y
- exp_x
> 15) {
962 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
965 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
966 if (exp_x
> exp_y
) { // to simplify the loop below,
967 // otherwise adjust the x significand upwards
968 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
969 mult_factor
[exp_x
- exp_y
]);
970 // return 1 if values are equal
971 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
975 // if postitive, return whichever significand abs is smaller
976 // (converse if negative)
977 res
= (((sig_n_prime
.w
[1] == 0)
978 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
982 // adjust the y significand upwards
983 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
984 mult_factor
[exp_y
- exp_x
]);
985 // return 1 if values are equal
986 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
990 // if positive, return whichever significand abs is smaller
991 // (converse if negative)
992 res
= (((sig_n_prime
.w
[1] > 0)
993 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
998 #if DECIMAL_CALL_BY_REFERENCE
1000 bid64_quiet_less_unordered (int *pres
, UINT64
* px
,
1002 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1008 bid64_quiet_less_unordered (UINT64 x
,
1009 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1014 UINT64 sig_x
, sig_y
;
1015 UINT128 sig_n_prime
;
1016 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1019 // if either number is NAN, the comparison is unordered : return 0
1020 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1021 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1022 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1028 // if all the bits are the same, these numbers are equal.
1034 if ((x
& MASK_INF
) == MASK_INF
) {
1035 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
1036 if ((x
& MASK_SIGN
) == MASK_SIGN
) {
1037 // x is -inf, so it is less than y unless y is -inf
1038 res
= (((y
& MASK_INF
) != MASK_INF
)
1039 || (y
& MASK_SIGN
) != MASK_SIGN
);
1042 // x is pos_inf, no way for it to be less than y
1046 } else if ((y
& MASK_INF
) == MASK_INF
) {
1048 // if y is +inf, x<y
1049 // if y is -inf, x>y
1050 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1053 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1054 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1055 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1056 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1057 if (sig_x
> 9999999999999999ull) {
1063 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1064 sig_x
= (x
& MASK_BINARY_SIG1
);
1067 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1068 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1069 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1070 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1071 if (sig_y
> 9999999999999999ull) {
1077 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1078 sig_y
= (y
& MASK_BINARY_SIG1
);
1083 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1084 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1085 // therefore ignore the exponent field
1086 // (Any non-canonical # is considered 0)
1087 if (non_canon_x
|| sig_x
== 0) {
1090 if (non_canon_y
|| sig_y
== 0) {
1093 if (x_is_zero
&& y_is_zero
) {
1094 // if both numbers are zero, they are equal
1097 } else if (x_is_zero
) {
1098 // if x is zero, it is lessthan if Y is positive
1099 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1101 } else if (y_is_zero
) {
1102 // if y is zero, X is less if it is negative
1103 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1106 // OPPOSITE SIGN (CASE5)
1107 // now, if the sign bits differ, x is less than if y is positive
1108 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1109 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1112 // REDUNDANT REPRESENTATIONS (CASE6)
1113 // if both components are either bigger or smaller
1114 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1115 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1118 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1119 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1122 // if exp_x is 15 greater than exp_y, no need for compensation
1123 if (exp_x
- exp_y
> 15) {
1124 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1125 // difference cannot be greater than 10^15
1128 // if exp_x is 15 less than exp_y, no need for compensation
1129 if (exp_y
- exp_x
> 15) {
1130 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1133 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1134 if (exp_x
> exp_y
) { // to simplify the loop below,
1135 // otherwise adjust the x significand upwards
1136 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1137 mult_factor
[exp_x
- exp_y
]);
1138 // return 0 if values are equal
1139 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1143 // if postitive, return whichever significand abs is smaller
1144 // (converse if negative)
1145 res
= (((sig_n_prime
.w
[1] == 0)
1146 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
1150 // adjust the y significand upwards
1151 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1152 mult_factor
[exp_y
- exp_x
]);
1153 // return 0 if values are equal
1154 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1158 // if positive, return whichever significand abs is smaller
1159 // (converse if negative)
1160 res
= (((sig_n_prime
.w
[1] > 0)
1161 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
1166 #if DECIMAL_CALL_BY_REFERENCE
1168 bid64_quiet_not_equal (int *pres
, UINT64
* px
,
1170 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1176 bid64_quiet_not_equal (UINT64 x
,
1177 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1181 int exp_x
, exp_y
, exp_t
;
1182 UINT64 sig_x
, sig_y
, sig_t
;
1183 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
, lcv
;
1186 // if either number is NAN, the comparison is unordered,
1187 // rather than equal : return 1
1188 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1189 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1190 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1196 // if all the bits are the same, these numbers are equivalent.
1202 if (((x
& MASK_INF
) == MASK_INF
) && ((y
& MASK_INF
) == MASK_INF
)) {
1203 res
= (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
);
1206 // ONE INFINITY (CASE3')
1207 if (((x
& MASK_INF
) == MASK_INF
) || ((y
& MASK_INF
) == MASK_INF
)) {
1211 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1212 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1213 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1214 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1215 if (sig_x
> 9999999999999999ull) {
1221 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1222 sig_x
= (x
& MASK_BINARY_SIG1
);
1226 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1227 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1228 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1229 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1230 if (sig_y
> 9999999999999999ull) {
1236 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1237 sig_y
= (y
& MASK_BINARY_SIG1
);
1243 // (+ZERO==-ZERO) => therefore ignore the sign
1244 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1245 // therefore ignore the exponent field
1246 // (Any non-canonical # is considered 0)
1247 if (non_canon_x
|| sig_x
== 0) {
1250 if (non_canon_y
|| sig_y
== 0) {
1254 if (x_is_zero
&& y_is_zero
) {
1257 } else if ((x_is_zero
&& !y_is_zero
) || (!x_is_zero
&& y_is_zero
)) {
1261 // OPPOSITE SIGN (CASE5)
1262 // now, if the sign bits differ => not equal : return 1
1263 if ((x
^ y
) & MASK_SIGN
) {
1267 // REDUNDANT REPRESENTATIONS (CASE6)
1268 if (exp_x
> exp_y
) { // to simplify the loop below,
1269 SWAP (exp_x
, exp_y
, exp_t
); // put the larger exp in y,
1270 SWAP (sig_x
, sig_y
, sig_t
); // and the smaller exp in x
1273 if (exp_y
- exp_x
> 15) {
1277 // difference cannot be greater than 10^16
1279 for (lcv
= 0; lcv
< (exp_y
- exp_x
); lcv
++) {
1281 // recalculate y's significand upwards
1283 if (sig_y
> 9999999999999999ull) {
1290 res
= sig_y
!= sig_x
;
1296 #if DECIMAL_CALL_BY_REFERENCE
1298 bid64_quiet_not_greater (int *pres
, UINT64
* px
,
1300 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1306 bid64_quiet_not_greater (UINT64 x
,
1307 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1312 UINT64 sig_x
, sig_y
;
1313 UINT128 sig_n_prime
;
1314 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1317 // if either number is NAN, the comparison is unordered,
1318 // rather than equal : return 0
1319 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1320 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1321 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1327 // if all the bits are the same, these numbers are equal (LESSEQUAL).
1333 if ((x
& MASK_INF
) == MASK_INF
) {
1334 // if x is neg infinity, it must be lessthan or equal to y return 1
1335 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
1339 // x is pos infinity, it is greater, unless y is positive
1340 // infinity => return y==pos_infinity
1342 res
= !(((y
& MASK_INF
) != MASK_INF
)
1343 || ((y
& MASK_SIGN
) == MASK_SIGN
));
1346 } else if ((y
& MASK_INF
) == MASK_INF
) {
1347 // x is finite, so if y is positive infinity, then x is less, return 1
1348 // if y is negative infinity, then x is greater, return 0
1350 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1354 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1355 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1356 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1357 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1358 if (sig_x
> 9999999999999999ull) {
1364 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1365 sig_x
= (x
& MASK_BINARY_SIG1
);
1369 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1370 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1371 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1372 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1373 if (sig_y
> 9999999999999999ull) {
1379 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1380 sig_y
= (y
& MASK_BINARY_SIG1
);
1386 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1387 // number is greater
1388 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1389 // therefore ignore the exponent field
1390 // (Any non-canonical # is considered 0)
1391 if (non_canon_x
|| sig_x
== 0) {
1394 if (non_canon_y
|| sig_y
== 0) {
1397 // if both numbers are zero, they are equal -> return 1
1398 if (x_is_zero
&& y_is_zero
) {
1402 // if x is zero, it is lessthan if Y is positive
1403 else if (x_is_zero
) {
1404 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1407 // if y is zero, X is less if it is negative
1408 else if (y_is_zero
) {
1409 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1412 // OPPOSITE SIGN (CASE5)
1413 // now, if the sign bits differ, x is less than if y is positive
1414 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1415 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
1418 // REDUNDANT REPRESENTATIONS (CASE6)
1419 // if both components are either bigger or smaller
1420 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1421 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1424 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1425 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1428 // if exp_x is 15 greater than exp_y, no need for compensation
1429 if (exp_x
- exp_y
> 15) {
1430 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1433 // difference cannot be greater than 10^15
1435 // if exp_x is 15 less than exp_y, no need for compensation
1436 if (exp_y
- exp_x
> 15) {
1437 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1440 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1441 if (exp_x
> exp_y
) { // to simplify the loop below,
1443 // otherwise adjust the x significand upwards
1444 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1445 mult_factor
[exp_x
- exp_y
]);
1447 // return 1 if values are equal
1448 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1452 // if postitive, return whichever significand abs is smaller
1453 // (converse if negative)
1455 res
= (((sig_n_prime
.w
[1] == 0)
1456 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
1461 // adjust the y significand upwards
1462 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1463 mult_factor
[exp_y
- exp_x
]);
1465 // return 1 if values are equal
1466 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1470 // if positive, return whichever significand abs is smaller
1471 // (converse if negative)
1473 res
= (((sig_n_prime
.w
[1] > 0)
1474 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
1480 #if DECIMAL_CALL_BY_REFERENCE
1482 bid64_quiet_not_less (int *pres
, UINT64
* px
,
1484 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1490 bid64_quiet_not_less (UINT64 x
,
1491 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1496 UINT64 sig_x
, sig_y
;
1497 UINT128 sig_n_prime
;
1498 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1501 // if either number is NAN, the comparison is unordered : return 1
1502 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1503 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1504 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1510 // if all the bits are the same, these numbers are equal.
1516 if ((x
& MASK_INF
) == MASK_INF
) {
1517 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1518 if ((x
& MASK_SIGN
) == MASK_SIGN
)
1519 // x is -inf, so it is less than y unless y is -inf
1521 res
= (((y
& MASK_INF
) == MASK_INF
)
1522 && (y
& MASK_SIGN
) == MASK_SIGN
);
1525 // x is pos_inf, no way for it to be less than y
1530 } else if ((y
& MASK_INF
) == MASK_INF
) {
1532 // if y is +inf, x<y
1533 // if y is -inf, x>y
1535 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1539 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1540 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1541 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1542 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1543 if (sig_x
> 9999999999999999ull) {
1549 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1550 sig_x
= (x
& MASK_BINARY_SIG1
);
1554 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1555 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1556 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1557 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1558 if (sig_y
> 9999999999999999ull) {
1564 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1565 sig_y
= (y
& MASK_BINARY_SIG1
);
1571 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1572 // number is greater
1573 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1574 // therefore ignore the exponent field
1575 // (Any non-canonical # is considered 0)
1576 if (non_canon_x
|| sig_x
== 0) {
1579 if (non_canon_y
|| sig_y
== 0) {
1582 // if both numbers are zero, they are equal
1583 if (x_is_zero
&& y_is_zero
) {
1587 // if x is zero, it is lessthan if Y is positive
1588 else if (x_is_zero
) {
1589 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1592 // if y is zero, X is less if it is negative
1593 else if (y_is_zero
) {
1594 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1597 // OPPOSITE SIGN (CASE5)
1598 // now, if the sign bits differ, x is less than if y is positive
1599 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1600 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1603 // REDUNDANT REPRESENTATIONS (CASE6)
1604 // if both components are either bigger or smaller
1605 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1606 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1609 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1610 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1613 // if exp_x is 15 greater than exp_y, no need for compensation
1614 if (exp_x
- exp_y
> 15) {
1615 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1618 // difference cannot be greater than 10^15
1620 // if exp_x is 15 less than exp_y, no need for compensation
1621 if (exp_y
- exp_x
> 15) {
1622 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1625 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1626 if (exp_x
> exp_y
) { // to simplify the loop below,
1628 // otherwise adjust the x significand upwards
1629 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1630 mult_factor
[exp_x
- exp_y
]);
1632 // return 0 if values are equal
1633 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1637 // if postitive, return whichever significand abs is smaller
1638 // (converse if negative)
1640 res
= (((sig_n_prime
.w
[1] == 0)
1641 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
1646 // adjust the y significand upwards
1647 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1648 mult_factor
[exp_y
- exp_x
]);
1650 // return 0 if values are equal
1651 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1655 // if positive, return whichever significand abs is smaller
1656 // (converse if negative)
1658 res
= (((sig_n_prime
.w
[1] > 0)
1659 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=
1665 #if DECIMAL_CALL_BY_REFERENCE
1667 bid64_quiet_ordered (int *pres
, UINT64
* px
,
1669 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1675 bid64_quiet_ordered (UINT64 x
,
1676 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1682 // if either number is NAN, the comparison is ordered, rather than equal : return 0
1683 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1684 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1685 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1695 #if DECIMAL_CALL_BY_REFERENCE
1697 bid64_quiet_unordered (int *pres
, UINT64
* px
,
1699 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1705 bid64_quiet_unordered (UINT64 x
,
1706 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1712 // if either number is NAN, the comparison is unordered,
1713 // rather than equal : return 0
1714 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1715 if ((x
& MASK_SNAN
) == MASK_SNAN
|| (y
& MASK_SNAN
) == MASK_SNAN
) {
1716 *pfpsf
|= INVALID_EXCEPTION
; // set exception if sNaN
1726 #if DECIMAL_CALL_BY_REFERENCE
1728 bid64_signaling_greater (int *pres
, UINT64
* px
,
1730 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1736 bid64_signaling_greater (UINT64 x
,
1737 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1742 UINT64 sig_x
, sig_y
;
1743 UINT128 sig_n_prime
;
1744 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1747 // if either number is NAN, the comparison is unordered,
1748 // rather than equal : return 0
1749 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1750 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
1755 // if all the bits are the same, these numbers are equal (not Greater).
1761 if ((x
& MASK_INF
) == MASK_INF
) {
1762 // if x is neg infinity, there is no way it is greater than y, return 0
1763 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
1767 // x is pos infinity, it is greater,
1768 // unless y is positive infinity => return y!=pos_infinity
1770 res
= (((y
& MASK_INF
) != MASK_INF
)
1771 || ((y
& MASK_SIGN
) == MASK_SIGN
));
1774 } else if ((y
& MASK_INF
) == MASK_INF
) {
1775 // x is finite, so if y is positive infinity, then x is less, return 0
1776 // if y is negative infinity, then x is greater, return 1
1778 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1782 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1783 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1784 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1785 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1786 if (sig_x
> 9999999999999999ull) {
1792 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1793 sig_x
= (x
& MASK_BINARY_SIG1
);
1797 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1798 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1799 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1800 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1801 if (sig_y
> 9999999999999999ull) {
1807 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1808 sig_y
= (y
& MASK_BINARY_SIG1
);
1814 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1815 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1816 // therefore ignore the exponent field
1817 // (Any non-canonical # is considered 0)
1818 if (non_canon_x
|| sig_x
== 0) {
1821 if (non_canon_y
|| sig_y
== 0) {
1824 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
1825 if (x_is_zero
&& y_is_zero
) {
1829 // is x is zero, it is greater if Y is negative
1830 else if (x_is_zero
) {
1831 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1834 // is y is zero, X is greater if it is positive
1835 else if (y_is_zero
) {
1836 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1839 // OPPOSITE SIGN (CASE5)
1840 // now, if the sign bits differ, x is greater if y is negative
1841 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
1842 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1845 // REDUNDANT REPRESENTATIONS (CASE6)
1847 // if both components are either bigger or smaller
1848 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
1849 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1852 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
1853 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1856 // if exp_x is 15 greater than exp_y, no need for compensation
1857 if (exp_x
- exp_y
> 15) {
1858 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
1861 // difference cannot be greater than 10^15
1863 // if exp_x is 15 less than exp_y, no need for compensation
1864 if (exp_y
- exp_x
> 15) {
1865 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
1868 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1869 if (exp_x
> exp_y
) { // to simplify the loop below,
1871 // otherwise adjust the x significand upwards
1872 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
1873 mult_factor
[exp_x
- exp_y
]);
1876 // if postitive, return whichever significand is larger
1877 // (converse if negative)
1878 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
1884 res
= (((sig_n_prime
.w
[1] > 0)
1885 || sig_n_prime
.w
[0] > sig_y
) ^ ((x
& MASK_SIGN
) ==
1890 // adjust the y significand upwards
1891 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
1892 mult_factor
[exp_y
- exp_x
]);
1894 // if postitive, return whichever significand is larger
1895 // (converse if negative)
1896 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
1901 res
= (((sig_n_prime
.w
[1] == 0)
1902 && (sig_x
> sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
1908 #if DECIMAL_CALL_BY_REFERENCE
1910 bid64_signaling_greater_equal (int *pres
, UINT64
* px
,
1912 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1918 bid64_signaling_greater_equal (UINT64 x
,
1919 UINT64 y _EXC_FLAGS_PARAM
1920 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
1924 UINT64 sig_x
, sig_y
;
1925 UINT128 sig_n_prime
;
1926 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
1929 // if either number is NAN, the comparison is unordered : return 1
1930 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
1931 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
1936 // if all the bits are the same, these numbers are equal.
1942 if ((x
& MASK_INF
) == MASK_INF
) {
1943 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1944 if ((x
& MASK_SIGN
) == MASK_SIGN
)
1945 // x is -inf, so it is less than y unless y is -inf
1947 res
= (((y
& MASK_INF
) == MASK_INF
)
1948 && (y
& MASK_SIGN
) == MASK_SIGN
);
1951 // x is pos_inf, no way for it to be less than y
1956 } else if ((y
& MASK_INF
) == MASK_INF
) {
1958 // if y is +inf, x<y
1959 // if y is -inf, x>y
1961 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
1965 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1966 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1967 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
1968 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1969 if (sig_x
> 9999999999999999ull) {
1975 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
1976 sig_x
= (x
& MASK_BINARY_SIG1
);
1980 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1981 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
1982 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
1983 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
1984 if (sig_y
> 9999999999999999ull) {
1990 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
1991 sig_y
= (y
& MASK_BINARY_SIG1
);
1997 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1998 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1999 // therefore ignore the exponent field
2000 // (Any non-canonical # is considered 0)
2001 if (non_canon_x
|| sig_x
== 0) {
2004 if (non_canon_y
|| sig_y
== 0) {
2007 // if both numbers are zero, they are equal
2008 if (x_is_zero
&& y_is_zero
) {
2012 // if x is zero, it is lessthan if Y is positive
2013 else if (x_is_zero
) {
2014 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2017 // if y is zero, X is less if it is negative
2018 else if (y_is_zero
) {
2019 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2022 // OPPOSITE SIGN (CASE5)
2023 // now, if the sign bits differ, x is less than if y is positive
2024 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2025 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2028 // REDUNDANT REPRESENTATIONS (CASE6)
2029 // if both components are either bigger or smaller
2030 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2031 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2034 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2035 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2038 // if exp_x is 15 greater than exp_y, no need for compensation
2039 if (exp_x
- exp_y
> 15) {
2040 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2043 // difference cannot be greater than 10^15
2045 // if exp_x is 15 less than exp_y, no need for compensation
2046 if (exp_y
- exp_x
> 15) {
2047 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2050 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2051 if (exp_x
> exp_y
) { // to simplify the loop below,
2053 // otherwise adjust the x significand upwards
2054 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2055 mult_factor
[exp_x
- exp_y
]);
2057 // return 1 if values are equal
2058 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2062 // if postitive, return whichever significand abs is smaller
2063 // (converse if negative)
2065 res
= (((sig_n_prime
.w
[1] == 0)
2066 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
2071 // adjust the y significand upwards
2072 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2073 mult_factor
[exp_y
- exp_x
]);
2075 // return 0 if values are equal
2076 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2080 // if positive, return whichever significand abs is smaller
2081 // (converse if negative)
2083 res
= (((sig_n_prime
.w
[1] > 0)
2084 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=
2090 #if DECIMAL_CALL_BY_REFERENCE
2092 bid64_signaling_greater_unordered (int *pres
, UINT64
* px
,
2094 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2100 bid64_signaling_greater_unordered (UINT64 x
,
2101 UINT64 y _EXC_FLAGS_PARAM
2102 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
2106 UINT64 sig_x
, sig_y
;
2107 UINT128 sig_n_prime
;
2108 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2111 // if either number is NAN, the comparison is unordered,
2112 // rather than equal : return 0
2113 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2114 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2119 // if all the bits are the same, these numbers are equal (not Greater).
2125 if ((x
& MASK_INF
) == MASK_INF
) {
2126 // if x is neg infinity, there is no way it is greater than y, return 0
2127 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
2131 // x is pos infinity, it is greater,
2132 // unless y is positive infinity => return y!=pos_infinity
2134 res
= (((y
& MASK_INF
) != MASK_INF
)
2135 || ((y
& MASK_SIGN
) == MASK_SIGN
));
2138 } else if ((y
& MASK_INF
) == MASK_INF
) {
2139 // x is finite, so if y is positive infinity, then x is less, return 0
2140 // if y is negative infinity, then x is greater, return 1
2142 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2146 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2147 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2148 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2149 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2150 if (sig_x
> 9999999999999999ull) {
2156 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2157 sig_x
= (x
& MASK_BINARY_SIG1
);
2161 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2162 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2163 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2164 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2165 if (sig_y
> 9999999999999999ull) {
2171 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2172 sig_y
= (y
& MASK_BINARY_SIG1
);
2178 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2179 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2180 // therefore ignore the exponent field
2181 // (Any non-canonical # is considered 0)
2182 if (non_canon_x
|| sig_x
== 0) {
2185 if (non_canon_y
|| sig_y
== 0) {
2188 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
2189 if (x_is_zero
&& y_is_zero
) {
2193 // is x is zero, it is greater if Y is negative
2194 else if (x_is_zero
) {
2195 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2198 // is y is zero, X is greater if it is positive
2199 else if (y_is_zero
) {
2200 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2203 // OPPOSITE SIGN (CASE5)
2204 // now, if the sign bits differ, x is greater if y is negative
2205 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2206 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
2209 // REDUNDANT REPRESENTATIONS (CASE6)
2211 // if both components are either bigger or smaller
2212 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2213 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2216 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2217 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2220 // if exp_x is 15 greater than exp_y, no need for compensation
2221 if (exp_x
- exp_y
> 15) {
2222 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2225 // difference cannot be greater than 10^15
2227 // if exp_x is 15 less than exp_y, no need for compensation
2228 if (exp_y
- exp_x
> 15) {
2229 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2232 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2233 if (exp_x
> exp_y
) { // to simplify the loop below,
2235 // otherwise adjust the x significand upwards
2236 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2237 mult_factor
[exp_x
- exp_y
]);
2239 // if postitive, return whichever significand is larger
2240 // (converse if negative)
2241 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2247 res
= (((sig_n_prime
.w
[1] > 0)
2248 || sig_n_prime
.w
[0] > sig_y
) ^ ((x
& MASK_SIGN
) ==
2253 // adjust the y significand upwards
2254 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2255 mult_factor
[exp_y
- exp_x
]);
2257 // if postitive, return whichever significand is larger
2258 // (converse if negative)
2259 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2264 res
= (((sig_n_prime
.w
[1] == 0)
2265 && (sig_x
> sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2271 #if DECIMAL_CALL_BY_REFERENCE
2273 bid64_signaling_less (int *pres
, UINT64
* px
,
2275 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2281 bid64_signaling_less (UINT64 x
,
2282 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2287 UINT64 sig_x
, sig_y
;
2288 UINT128 sig_n_prime
;
2289 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2292 // if either number is NAN, the comparison is unordered : return 0
2293 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2294 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2299 // if all the bits are the same, these numbers are equal.
2305 if ((x
& MASK_INF
) == MASK_INF
) {
2306 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2307 if ((x
& MASK_SIGN
) == MASK_SIGN
)
2308 // x is -inf, so it is less than y unless y is -inf
2310 res
= (((y
& MASK_INF
) != MASK_INF
)
2311 || (y
& MASK_SIGN
) != MASK_SIGN
);
2314 // x is pos_inf, no way for it to be less than y
2319 } else if ((y
& MASK_INF
) == MASK_INF
) {
2321 // if y is +inf, x<y
2322 // if y is -inf, x>y
2324 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2328 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2329 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2330 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2331 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2332 if (sig_x
> 9999999999999999ull) {
2338 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2339 sig_x
= (x
& MASK_BINARY_SIG1
);
2343 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2344 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2345 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2346 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2347 if (sig_y
> 9999999999999999ull) {
2353 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2354 sig_y
= (y
& MASK_BINARY_SIG1
);
2360 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2361 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2362 // therefore ignore the exponent field
2363 // (Any non-canonical # is considered 0)
2364 if (non_canon_x
|| sig_x
== 0) {
2367 if (non_canon_y
|| sig_y
== 0) {
2370 // if both numbers are zero, they are equal
2371 if (x_is_zero
&& y_is_zero
) {
2375 // if x is zero, it is lessthan if Y is positive
2376 else if (x_is_zero
) {
2377 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2380 // if y is zero, X is less if it is negative
2381 else if (y_is_zero
) {
2382 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2385 // OPPOSITE SIGN (CASE5)
2386 // now, if the sign bits differ, x is less than if y is positive
2387 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2388 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2391 // REDUNDANT REPRESENTATIONS (CASE6)
2392 // if both components are either bigger or smaller
2393 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2394 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2397 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2398 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2401 // if exp_x is 15 greater than exp_y, no need for compensation
2402 if (exp_x
- exp_y
> 15) {
2403 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2406 // difference cannot be greater than 10^15
2408 // if exp_x is 15 less than exp_y, no need for compensation
2409 if (exp_y
- exp_x
> 15) {
2410 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2413 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2414 if (exp_x
> exp_y
) { // to simplify the loop below,
2416 // otherwise adjust the x significand upwards
2417 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2418 mult_factor
[exp_x
- exp_y
]);
2420 // return 0 if values are equal
2421 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2425 // if postitive, return whichever significand abs is smaller
2426 // (converse if negative)
2428 res
= (((sig_n_prime
.w
[1] == 0)
2429 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2434 // adjust the y significand upwards
2435 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2436 mult_factor
[exp_y
- exp_x
]);
2438 // return 0 if values are equal
2439 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2443 // if positive, return whichever significand abs is smaller
2444 // (converse if negative)
2446 res
= (((sig_n_prime
.w
[1] > 0)
2447 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2453 #if DECIMAL_CALL_BY_REFERENCE
2455 bid64_signaling_less_equal (int *pres
, UINT64
* px
,
2457 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2463 bid64_signaling_less_equal (UINT64 x
,
2464 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2469 UINT64 sig_x
, sig_y
;
2470 UINT128 sig_n_prime
;
2471 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2474 // if either number is NAN, the comparison is unordered,
2475 // rather than equal : return 0
2476 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2477 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2482 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2488 if ((x
& MASK_INF
) == MASK_INF
) {
2489 // if x is neg infinity, it must be lessthan or equal to y return 1
2490 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
2494 // x is pos infinity, it is greater,
2495 // unless y is positive infinity => return y==pos_infinity
2497 res
= !(((y
& MASK_INF
) != MASK_INF
)
2498 || ((y
& MASK_SIGN
) == MASK_SIGN
));
2501 } else if ((y
& MASK_INF
) == MASK_INF
) {
2502 // x is finite, so if y is positive infinity, then x is less, return 1
2503 // if y is negative infinity, then x is greater, return 0
2505 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2509 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2510 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2511 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2512 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2513 if (sig_x
> 9999999999999999ull) {
2519 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2520 sig_x
= (x
& MASK_BINARY_SIG1
);
2524 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2525 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2526 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2527 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2528 if (sig_y
> 9999999999999999ull) {
2534 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2535 sig_y
= (y
& MASK_BINARY_SIG1
);
2541 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2542 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2543 // therefore ignore the exponent field
2544 // (Any non-canonical # is considered 0)
2545 if (non_canon_x
|| sig_x
== 0) {
2548 if (non_canon_y
|| sig_y
== 0) {
2551 // if both numbers are zero, they are equal -> return 1
2552 if (x_is_zero
&& y_is_zero
) {
2556 // if x is zero, it is lessthan if Y is positive
2557 else if (x_is_zero
) {
2558 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2561 // if y is zero, X is less if it is negative
2562 else if (y_is_zero
) {
2563 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2566 // OPPOSITE SIGN (CASE5)
2567 // now, if the sign bits differ, x is less than if y is positive
2568 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2569 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2572 // REDUNDANT REPRESENTATIONS (CASE6)
2573 // if both components are either bigger or smaller
2574 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2575 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2578 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2579 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2582 // if exp_x is 15 greater than exp_y, no need for compensation
2583 if (exp_x
- exp_y
> 15) {
2584 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2587 // difference cannot be greater than 10^15
2589 // if exp_x is 15 less than exp_y, no need for compensation
2590 if (exp_y
- exp_x
> 15) {
2591 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2594 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2595 if (exp_x
> exp_y
) { // to simplify the loop below,
2597 // otherwise adjust the x significand upwards
2598 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2599 mult_factor
[exp_x
- exp_y
]);
2601 // return 1 if values are equal
2602 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2606 // if postitive, return whichever significand abs is smaller
2607 // (converse if negative)
2609 res
= (((sig_n_prime
.w
[1] == 0)
2610 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2615 // adjust the y significand upwards
2616 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2617 mult_factor
[exp_y
- exp_x
]);
2619 // return 1 if values are equal
2620 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2624 // if positive, return whichever significand abs is smaller
2625 // (converse if negative)
2627 res
= (((sig_n_prime
.w
[1] > 0)
2628 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2634 #if DECIMAL_CALL_BY_REFERENCE
2636 bid64_signaling_less_unordered (int *pres
, UINT64
* px
,
2638 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2644 bid64_signaling_less_unordered (UINT64 x
,
2645 UINT64 y _EXC_FLAGS_PARAM
2646 _EXC_MASKS_PARAM _EXC_INFO_PARAM
) {
2650 UINT64 sig_x
, sig_y
;
2651 UINT128 sig_n_prime
;
2652 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2655 // if either number is NAN, the comparison is unordered : return 0
2656 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2657 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2662 // if all the bits are the same, these numbers are equal.
2668 if ((x
& MASK_INF
) == MASK_INF
) {
2669 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2670 if ((x
& MASK_SIGN
) == MASK_SIGN
)
2671 // x is -inf, so it is less than y unless y is -inf
2673 res
= (((y
& MASK_INF
) != MASK_INF
)
2674 || (y
& MASK_SIGN
) != MASK_SIGN
);
2677 // x is pos_inf, no way for it to be less than y
2682 } else if ((y
& MASK_INF
) == MASK_INF
) {
2684 // if y is +inf, x<y
2685 // if y is -inf, x>y
2687 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2691 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2692 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2693 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2694 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2695 if (sig_x
> 9999999999999999ull) {
2701 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2702 sig_x
= (x
& MASK_BINARY_SIG1
);
2706 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2707 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2708 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2709 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2710 if (sig_y
> 9999999999999999ull) {
2716 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2717 sig_y
= (y
& MASK_BINARY_SIG1
);
2723 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2724 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2725 // therefore ignore the exponent field
2726 // (Any non-canonical # is considered 0)
2727 if (non_canon_x
|| sig_x
== 0) {
2730 if (non_canon_y
|| sig_y
== 0) {
2733 // if both numbers are zero, they are equal
2734 if (x_is_zero
&& y_is_zero
) {
2738 // if x is zero, it is lessthan if Y is positive
2739 else if (x_is_zero
) {
2740 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2743 // if y is zero, X is less if it is negative
2744 else if (y_is_zero
) {
2745 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2748 // OPPOSITE SIGN (CASE5)
2749 // now, if the sign bits differ, x is less than if y is positive
2750 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2751 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2754 // REDUNDANT REPRESENTATIONS (CASE6)
2755 // if both components are either bigger or smaller
2756 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2757 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2760 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2761 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2764 // if exp_x is 15 greater than exp_y, no need for compensation
2765 if (exp_x
- exp_y
> 15) {
2766 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2769 // difference cannot be greater than 10^15
2771 // if exp_x is 15 less than exp_y, no need for compensation
2772 if (exp_y
- exp_x
> 15) {
2773 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2776 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2777 if (exp_x
> exp_y
) { // to simplify the loop below,
2779 // otherwise adjust the x significand upwards
2780 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2781 mult_factor
[exp_x
- exp_y
]);
2783 // return 0 if values are equal
2784 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2788 // if postitive, return whichever significand abs is smaller
2789 // (converse if negative)
2791 res
= (((sig_n_prime
.w
[1] == 0)
2792 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2797 // adjust the y significand upwards
2798 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2799 mult_factor
[exp_y
- exp_x
]);
2801 // return 0 if values are equal
2802 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2806 // if positive, return whichever significand abs is smaller
2807 // (converse if negative)
2809 res
= (((sig_n_prime
.w
[1] > 0)
2810 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2816 #if DECIMAL_CALL_BY_REFERENCE
2818 bid64_signaling_not_greater (int *pres
, UINT64
* px
,
2820 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2826 bid64_signaling_not_greater (UINT64 x
,
2827 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2832 UINT64 sig_x
, sig_y
;
2833 UINT128 sig_n_prime
;
2834 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
2837 // if either number is NAN, the comparison is unordered,
2838 // rather than equal : return 0
2839 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
2840 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
2845 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2851 if ((x
& MASK_INF
) == MASK_INF
) {
2852 // if x is neg infinity, it must be lessthan or equal to y return 1
2853 if (((x
& MASK_SIGN
) == MASK_SIGN
)) {
2857 // x is pos infinity, it is greater,
2858 // unless y is positive infinity => return y==pos_infinity
2860 res
= !(((y
& MASK_INF
) != MASK_INF
)
2861 || ((y
& MASK_SIGN
) == MASK_SIGN
));
2864 } else if ((y
& MASK_INF
) == MASK_INF
) {
2865 // x is finite, so if y is positive infinity, then x is less, return 1
2866 // if y is negative infinity, then x is greater, return 0
2868 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2872 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2873 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2874 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
2875 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2876 if (sig_x
> 9999999999999999ull) {
2882 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
2883 sig_x
= (x
& MASK_BINARY_SIG1
);
2887 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2888 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
2889 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
2890 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
2891 if (sig_y
> 9999999999999999ull) {
2897 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
2898 sig_y
= (y
& MASK_BINARY_SIG1
);
2904 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2905 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2906 // therefore ignore the exponent field
2907 // (Any non-canonical # is considered 0)
2908 if (non_canon_x
|| sig_x
== 0) {
2911 if (non_canon_y
|| sig_y
== 0) {
2914 // if both numbers are zero, they are equal -> return 1
2915 if (x_is_zero
&& y_is_zero
) {
2919 // if x is zero, it is lessthan if Y is positive
2920 else if (x_is_zero
) {
2921 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2924 // if y is zero, X is less if it is negative
2925 else if (y_is_zero
) {
2926 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2929 // OPPOSITE SIGN (CASE5)
2930 // now, if the sign bits differ, x is less than if y is positive
2931 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
2932 res
= ((y
& MASK_SIGN
) != MASK_SIGN
);
2935 // REDUNDANT REPRESENTATIONS (CASE6)
2936 // if both components are either bigger or smaller
2937 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
2938 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2941 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
2942 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2945 // if exp_x is 15 greater than exp_y, no need for compensation
2946 if (exp_x
- exp_y
> 15) {
2947 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
2950 // difference cannot be greater than 10^15
2952 // if exp_x is 15 less than exp_y, no need for compensation
2953 if (exp_y
- exp_x
> 15) {
2954 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
2957 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2958 if (exp_x
> exp_y
) { // to simplify the loop below,
2960 // otherwise adjust the x significand upwards
2961 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
2962 mult_factor
[exp_x
- exp_y
]);
2964 // return 1 if values are equal
2965 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
2969 // if postitive, return whichever significand abs is smaller
2970 // (converse if negative)
2972 res
= (((sig_n_prime
.w
[1] == 0)
2973 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) ==
2978 // adjust the y significand upwards
2979 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
2980 mult_factor
[exp_y
- exp_x
]);
2982 // return 1 if values are equal
2983 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
2987 // if positive, return whichever significand abs is smaller
2988 // (converse if negative)
2990 res
= (((sig_n_prime
.w
[1] > 0)
2991 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) ==
2997 #if DECIMAL_CALL_BY_REFERENCE
2999 bid64_signaling_not_less (int *pres
, UINT64
* px
,
3001 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3007 bid64_signaling_not_less (UINT64 x
,
3008 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3013 UINT64 sig_x
, sig_y
;
3014 UINT128 sig_n_prime
;
3015 char x_is_zero
= 0, y_is_zero
= 0, non_canon_x
, non_canon_y
;
3018 // if either number is NAN, the comparison is unordered : return 1
3019 if (((x
& MASK_NAN
) == MASK_NAN
) || ((y
& MASK_NAN
) == MASK_NAN
)) {
3020 *pfpsf
|= INVALID_EXCEPTION
; // set invalid exception if NaN
3025 // if all the bits are the same, these numbers are equal.
3031 if ((x
& MASK_INF
) == MASK_INF
) {
3032 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
3033 if ((x
& MASK_SIGN
) == MASK_SIGN
)
3034 // x is -inf, so it is less than y unless y is -inf
3036 res
= (((y
& MASK_INF
) == MASK_INF
)
3037 && (y
& MASK_SIGN
) == MASK_SIGN
);
3040 // x is pos_inf, no way for it to be less than y
3045 } else if ((y
& MASK_INF
) == MASK_INF
) {
3047 // if y is +inf, x<y
3048 // if y is -inf, x>y
3050 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
3054 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3055 if ((x
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
3056 exp_x
= (x
& MASK_BINARY_EXPONENT2
) >> 51;
3057 sig_x
= (x
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
3058 if (sig_x
> 9999999999999999ull) {
3064 exp_x
= (x
& MASK_BINARY_EXPONENT1
) >> 53;
3065 sig_x
= (x
& MASK_BINARY_SIG1
);
3069 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3070 if ((y
& MASK_STEERING_BITS
) == MASK_STEERING_BITS
) {
3071 exp_y
= (y
& MASK_BINARY_EXPONENT2
) >> 51;
3072 sig_y
= (y
& MASK_BINARY_SIG2
) | MASK_BINARY_OR2
;
3073 if (sig_y
> 9999999999999999ull) {
3079 exp_y
= (y
& MASK_BINARY_EXPONENT1
) >> 53;
3080 sig_y
= (y
& MASK_BINARY_SIG1
);
3086 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
3087 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
3088 // therefore ignore the exponent field
3089 // (Any non-canonical # is considered 0)
3090 if (non_canon_x
|| sig_x
== 0) {
3093 if (non_canon_y
|| sig_y
== 0) {
3096 // if both numbers are zero, they are equal
3097 if (x_is_zero
&& y_is_zero
) {
3101 // if x is zero, it is lessthan if Y is positive
3102 else if (x_is_zero
) {
3103 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
3106 // if y is zero, X is less if it is negative
3107 else if (y_is_zero
) {
3108 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
3111 // OPPOSITE SIGN (CASE5)
3112 // now, if the sign bits differ, x is less than if y is positive
3113 if (((x
^ y
) & MASK_SIGN
) == MASK_SIGN
) {
3114 res
= ((y
& MASK_SIGN
) == MASK_SIGN
);
3117 // REDUNDANT REPRESENTATIONS (CASE6)
3118 // if both components are either bigger or smaller
3119 if (sig_x
> sig_y
&& exp_x
>= exp_y
) {
3120 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
3123 if (sig_x
< sig_y
&& exp_x
<= exp_y
) {
3124 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
3127 // if exp_x is 15 greater than exp_y, no need for compensation
3128 if (exp_x
- exp_y
> 15) {
3129 res
= ((x
& MASK_SIGN
) != MASK_SIGN
);
3132 // difference cannot be greater than 10^15
3134 // if exp_x is 15 less than exp_y, no need for compensation
3135 if (exp_y
- exp_x
> 15) {
3136 res
= ((x
& MASK_SIGN
) == MASK_SIGN
);
3139 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
3140 if (exp_x
> exp_y
) { // to simplify the loop below,
3142 // otherwise adjust the x significand upwards
3143 __mul_64x64_to_128MACH (sig_n_prime
, sig_x
,
3144 mult_factor
[exp_x
- exp_y
]);
3146 // return 0 if values are equal
3147 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_y
)) {
3151 // if postitive, return whichever significand abs is smaller
3152 // (converse if negative)
3154 res
= (((sig_n_prime
.w
[1] == 0)
3155 && sig_n_prime
.w
[0] < sig_y
) ^ ((x
& MASK_SIGN
) !=
3160 // adjust the y significand upwards
3161 __mul_64x64_to_128MACH (sig_n_prime
, sig_y
,
3162 mult_factor
[exp_y
- exp_x
]);
3164 // return 0 if values are equal
3165 if (sig_n_prime
.w
[1] == 0 && (sig_n_prime
.w
[0] == sig_x
)) {
3169 // if positive, return whichever significand abs is smaller
3170 // (converse if negative)
3172 res
= (((sig_n_prime
.w
[1] > 0)
3173 || (sig_x
< sig_n_prime
.w
[0])) ^ ((x
& MASK_SIGN
) !=