Skip to content

Commit c63fa3f

Browse files
committed
Use < 0 instead of == -1 for comparisons
1 parent 5387690 commit c63fa3f

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

core/math/big/internal.odin

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,22 +1199,22 @@ internal_cmp_mag :: internal_compare_magnitude
11991199
bool := a < b
12001200
*/
12011201
internal_int_less_than :: #force_inline proc(a, b: ^Int) -> (less_than: bool) {
1202-
return internal_cmp(a, b) == -1
1202+
return internal_cmp(a, b) < 0
12031203
}
12041204

12051205
/*
12061206
bool := a < b
12071207
*/
12081208
internal_int_less_than_digit :: #force_inline proc(a: ^Int, b: DIGIT) -> (less_than: bool) {
1209-
return internal_cmp_digit(a, b) == -1
1209+
return internal_cmp_digit(a, b) < 0
12101210
}
12111211

12121212
/*
12131213
bool := |a| < |b|
12141214
Compares the magnitudes only, ignores the sign.
12151215
*/
12161216
internal_int_less_than_abs :: #force_inline proc(a, b: ^Int) -> (less_than: bool) {
1217-
return internal_cmp_mag(a, b) == -1
1217+
return internal_cmp_mag(a, b) < 0
12181218
}
12191219

12201220
internal_less_than :: proc {
@@ -2933,7 +2933,7 @@ internal_int_zero_unused :: #force_inline proc(dest: ^Int, old_used := -1) {
29332933
If we don't pass the number of previously used DIGITs, we zero all remaining ones.
29342934
*/
29352935
zero_count: int
2936-
if old_used == -1 {
2936+
if old_used < 0 {
29372937
zero_count = len(dest.digit) - dest.used
29382938
} else {
29392939
zero_count = old_used - dest.used

core/math/big/prime.odin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ internal_random_prime :: proc(a: ^Int, size_in_bits: int, trials: int, flags :=
12071207
/*
12081208
Automatically choose the number of Rabin-Miller trials?
12091209
*/
1210-
if trials == -1 {
1210+
if trials < 0 {
12111211
trials = number_of_rabin_miller_trials(size_in_bits)
12121212
}
12131213

core/math/big/private.odin

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ _private_int_log :: proc(a: ^Int, base: DIGIT, allocator := context.allocator) -
16621662
defer internal_destroy(bracket_low, bracket_high, bracket_mid, t, bi_base)
16631663

16641664
ic := #force_inline internal_cmp(a, base)
1665-
if ic == -1 || ic == 0 {
1665+
if ic <= 0 {
16661666
return 1 if ic == 0 else 0, nil
16671667
}
16681668
defer if err != nil {
@@ -2492,9 +2492,9 @@ _private_int_exponent_mod :: proc(res, G, X, P: ^Int, redmode: int, allocator :=
24922492
bitcnt -= 1
24932493
if bitcnt == 0 {
24942494
/*
2495-
If digidx == -1 we are out of digits.
2495+
If digidx < 0 we are out of digits.
24962496
*/
2497-
if digidx == -1 { break }
2497+
if digidx < 0 { break }
24982498

24992499
/*
25002500
Read next digit and reset the bitcnt.
@@ -2748,9 +2748,9 @@ _private_int_exponent_mod_fast :: proc(res, G, X, P: ^Int, redmode: int, allocat
27482748
bitcnt -= 1
27492749
if bitcnt == 0 {
27502750
/*
2751-
If digidx == -1 we are out of digits so break.
2751+
If digidx < 0 we are out of digits so break.
27522752
*/
2753-
if digidx == -1 { break }
2753+
if digidx < 0 { break }
27542754

27552755
/*
27562756
Read next digit and reset the bitcnt.

core/math/big/public.odin

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ int_less_than :: #force_inline proc(a, b: ^Int, allocator := context.allocator)
593593
c: int
594594
c, err = cmp(a, b)
595595

596-
return c == -1, err
596+
return c < 0, err
597597
}
598598

599599
/*
@@ -608,7 +608,7 @@ int_less_than_digit :: #force_inline proc(a: ^Int, b: DIGIT, allocator := contex
608608
c: int
609609
c, err = cmp(a, b)
610610

611-
return c == -1, err
611+
return c < 0, err
612612
}
613613

614614
/*
@@ -624,7 +624,7 @@ int_less_than_abs :: #force_inline proc(a, b: ^Int, allocator := context.allocat
624624
c: int
625625
c, err = cmp_mag(a, b)
626626

627-
return c == -1, err
627+
return c < 0, err
628628
}
629629

630630
less_than :: proc {

core/math/big/radix.odin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int_itoa_raw :: proc(a: ^Int, radix: i8, buffer: []u8, size := int(-1), zero_ter
110110
/*
111111
We weren't given a size. Let's compute it.
112112
*/
113-
if size == -1 {
113+
if size < 0 {
114114
size = radix_size(a, radix, zero_terminate) or_return
115115
}
116116

0 commit comments

Comments
 (0)