Skip to content

Commit

Permalink
2 logic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomHashTags committed Apr 28, 2023
1 parent 10c8fd1 commit 63adbd6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/huge-numbers/HugeDecimal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public extension HugeDecimal {

/// - Warning: This doesn't add the resulting quotient to the `left` variable.
static func += (left: inout HugeDecimal, right: HugeDecimal) { // TODO: support addition of repeating numbers
left.value += right.value
left = HugeDecimal.add(left: left, right: right).result
}
}
internal extension HugeDecimal {
Expand Down Expand Up @@ -167,7 +167,7 @@ public extension HugeDecimal {
}

static func -= (left: inout HugeDecimal, right: HugeDecimal) { // TODO: support subtraction of repeating numbers
left.value -= right.value
left += -right
}
}
/*
Expand Down
6 changes: 6 additions & 0 deletions Sources/huge-numbers/HugeInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,12 @@ public extension HugeInt {
static func / (dividend: HugeInt, divisor: HugeInt) -> (quotient: HugeInt, remainder: HugeRemainder?) {
if dividend == HugeInt.zero {
return (HugeInt.zero, divisor == HugeInt.zero ? nil : HugeRemainder(dividend: dividend, divisor: divisor))
} else if divisor.numbers == [1] {
if divisor.is_negative {
return (-dividend, nil)
} else {
return (dividend, nil)
}
}
guard dividend >= divisor else {
return (HugeInt.zero, HugeRemainder(dividend: dividend, divisor: divisor))
Expand Down

0 comments on commit 63adbd6

Please sign in to comment.