Skip to content

Commit

Permalink
Update JsonNumber.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
SusanDoggie committed Feb 26, 2022
1 parent 5c0ac19 commit 378b122
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions Sources/DoggieCore/Json/JsonNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,6 @@ extension Json.Number {

extension Json.Number {

@inlinable
static func _pow(_ x: Decimal, _ n: UInt64) -> Decimal {
if x == 0 { return 0 }
if n == 0 { return 1 }
return n & 1 == 1 ? x * _pow(x * x, n >> 1) : _pow(x * x, n >> 1)
}

@inlinable
static func _pow<T: FixedWidthInteger>(_ x: T, _ n: UInt64) -> T? {
if x == 0 { return 0 }
Expand All @@ -390,7 +383,7 @@ extension Json.Number {
switch (lhs.normalized, rhs.normalized) {
case let (.signed(_lhs), .unsigned(_rhs)): return _pow(_lhs, _rhs).map { .init($0) } ?? .init(Double.pow(lhs._doubleValue, rhs._doubleValue))
case let (.unsigned(_lhs), .unsigned(_rhs)): return _pow(_lhs, _rhs).map { .init($0) } ?? .init(Double.pow(lhs._doubleValue, rhs._doubleValue))
case let (.decimal(_lhs), .unsigned(_rhs)): return .init(_pow(_lhs, _rhs))
case let (.decimal(_lhs), .unsigned(_rhs)): return Int(exactly: _rhs).map { .init(Foundation.pow(_lhs, $0)) } ?? .init(Double.pow(lhs._doubleValue, rhs._doubleValue))
default: return .init(Double.pow(lhs._doubleValue, rhs._doubleValue))
}
}
Expand Down

0 comments on commit 378b122

Please sign in to comment.