42
42
int _bc_do_compare (bc_num n1 , bc_num n2 , bool use_sign , bool ignore_last )
43
43
{
44
44
char * n1ptr , * n2ptr ;
45
+ int result_n1_is_large = -1 ;
45
46
46
47
/* First, compare signs. */
47
- if (use_sign && n1 -> n_sign != n2 -> n_sign ) {
48
+ if (use_sign ) {
48
49
if (n1 -> n_sign == PLUS ) {
49
- /* Positive N1 > Negative N2 */
50
- return (1 );
50
+ if (n1 -> n_sign != n2 -> n_sign ) {
51
+ return 1 ;
52
+ }
53
+ result_n1_is_large = 1 ;
51
54
} else {
52
- /* Negative N1 < Positive N1 */
53
- return (-1 );
55
+ if (n1 -> n_sign != n2 -> n_sign ) {
56
+ return -1 ;
57
+ }
54
58
}
59
+ } else {
60
+ result_n1_is_large = 1 ;
55
61
}
56
62
57
63
/* Now compare the magnitude. */
58
64
if (n1 -> n_len != n2 -> n_len ) {
59
65
if (n1 -> n_len > n2 -> n_len ) {
60
66
/* Magnitude of n1 > n2. */
61
- if (!use_sign || n1 -> n_sign == PLUS ) {
62
- return (1 );
63
- } else {
64
- return (-1 );
65
- }
67
+ return result_n1_is_large ;
66
68
} else {
67
69
/* Magnitude of n1 < n2. */
68
- if (!use_sign || n1 -> n_sign == PLUS ) {
69
- return (-1 );
70
- } else {
71
- return (1 );
72
- }
70
+ return - result_n1_is_large ;
73
71
}
74
72
}
75
73
@@ -91,18 +89,10 @@ int _bc_do_compare(bc_num n1, bc_num n2, bool use_sign, bool ignore_last)
91
89
if (count != 0 ) {
92
90
if (* n1ptr > * n2ptr ) {
93
91
/* Magnitude of n1 > n2. */
94
- if (!use_sign || n1 -> n_sign == PLUS ) {
95
- return (1 );
96
- } else {
97
- return (-1 );
98
- }
92
+ return result_n1_is_large ;
99
93
} else {
100
94
/* Magnitude of n1 < n2. */
101
- if (!use_sign || n1 -> n_sign == PLUS ) {
102
- return (-1 );
103
- } else {
104
- return (1 );
105
- }
95
+ return - result_n1_is_large ;
106
96
}
107
97
}
108
98
@@ -112,22 +102,14 @@ int _bc_do_compare(bc_num n1, bc_num n2, bool use_sign, bool ignore_last)
112
102
for (count = n1 -> n_scale - n2 -> n_scale ; count > 0 ; count -- ) {
113
103
if (* n1ptr ++ != 0 ) {
114
104
/* Magnitude of n1 > n2. */
115
- if (!use_sign || n1 -> n_sign == PLUS ) {
116
- return (1 );
117
- } else {
118
- return (-1 );
119
- }
105
+ return result_n1_is_large ;
120
106
}
121
107
}
122
108
} else {
123
109
for (count = n2 -> n_scale - n1 -> n_scale ; count > 0 ; count -- ) {
124
110
if (* n2ptr ++ != 0 ) {
125
111
/* Magnitude of n1 < n2. */
126
- if (!use_sign || n1 -> n_sign == PLUS ) {
127
- return (-1 );
128
- } else {
129
- return (1 );
130
- }
112
+ return - result_n1_is_large ;
131
113
}
132
114
}
133
115
}
0 commit comments