Skip to content

Commit

Permalink
Reorganize source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentey committed Aug 11, 2017
1 parent 41ef5e4 commit 2c10e65
Show file tree
Hide file tree
Showing 23 changed files with 839 additions and 786 deletions.
342 changes: 181 additions & 161 deletions BigInt.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion sources/BigUInt Addition.swift → sources/Addition.swift
@@ -1,5 +1,5 @@
//
// BigUInt Addition.swift
// Addition.swift
// BigInt
//
// Created by Károly Lőrentey on 2016-01-03.
Expand Down Expand Up @@ -92,3 +92,35 @@ extension BigUInt {
a.add(b, shiftedBy: 0)
}
}

extension BigInt {
/// Add `a` to `b` and return the result.
public static func +(a: BigInt, b: BigInt) -> BigInt {
switch (a.sign, b.sign) {
case (.plus, .plus):
return BigInt(sign: .plus, magnitude: a.magnitude + b.magnitude)
case (.minus, .minus):
return BigInt(sign: .minus, magnitude: a.magnitude + b.magnitude)
case (.plus, .minus):
if a.magnitude >= b.magnitude {
return BigInt(sign: .plus, magnitude: a.magnitude - b.magnitude)
}
else {
return BigInt(sign: .minus, magnitude: b.magnitude - a.magnitude)
}
case (.minus, .plus):
if b.magnitude >= a.magnitude {
return BigInt(sign: .plus, magnitude: b.magnitude - a.magnitude)
}
else {
return BigInt(sign: .minus, magnitude: a.magnitude - b.magnitude)
}
}
}

/// Add `b` to `a` in place.
public static func +=(a: inout BigInt, b: BigInt) {
a = a + b
}
}

0 comments on commit 2c10e65

Please sign in to comment.