File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -598,6 +598,16 @@ fn test_addition() {
598
598
}
599
599
}
600
600
601
+ fn test_add_sign () {
602
+ for a in - 10 .. 10 {
603
+ for b in - 10 .. 10 {
604
+ big_a := big.integer_from_int (a)
605
+ big_b := big.integer_from_int (b)
606
+ assert (big_a + big_b).str () == (a + b).str ()
607
+ }
608
+ }
609
+ }
610
+
601
611
fn test_subtraction () {
602
612
for t in sub_test_data {
603
613
assert t.minuend.parse () - t.subtrahend.parse () == t.difference.parse (), 't.minuend: ${t.minuend} - t.subtrahend: ${t.subtrahend} '
Original file line number Diff line number Diff line change @@ -316,18 +316,12 @@ pub fn (augend Integer) + (addend Integer) Integer {
316
316
if augend.signum == addend.signum {
317
317
return augend.add (addend)
318
318
}
319
- // Unequal signs, left is negative:
320
- if augend.signum == - 1 {
321
- // -1 + 5 == 5 - 1
322
- return addend.subtract (augend)
323
- }
324
- // Unequal signs, left is positive:
325
- res := augend.subtract (addend)
326
- cmp := augend.abs_cmp (addend)
327
- if cmp < 0 {
328
- return res.neg ()
329
- }
330
- return res
319
+ // Unequal signs
320
+ if augend.abs_cmp (addend) < 0 {
321
+ return augend.subtract (addend).neg ()
322
+ } else {
323
+ return augend.subtract (addend)
324
+ }
331
325
}
332
326
333
327
// - returns the difference of the integers `minuend` and `subtrahend`
You can’t perform that action at this time.
0 commit comments