Skip to content

Commit

Permalink
Merge pull request #10 from SomeRandomiOSDev/1.1.1
Browse files Browse the repository at this point in the history
Release 1.1.1
  • Loading branch information
SomeRandomiOSDev authored Feb 24, 2020
2 parents 862708b + b8b2ef4 commit a6b929e
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Complex.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Complex"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "Swift Complex Number"
s.description = <<-DESC
A lightweight framework designed for representing and working with complex numbers for iOS, macOS, tvOS, and watchOS.
Expand Down
17 changes: 14 additions & 3 deletions Sources/Complex/Complex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,27 @@ extension Complex: Decodable where Scalar: Decodable {

// MARK: - Complex BinaryInteger Extensions

extension Complex {

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@usableFromInline
internal typealias LargestFloatType = Float80
#else
@usableFromInline
internal typealias LargestFloatType = Double
#endif
}

extension Complex where Scalar: BinaryInteger {

@_transparent
public var modulus: Scalar {
return Scalar(sqrt(Float80(real * real + imaginary * imaginary)))
return Scalar(sqrt(LargestFloatType(real * real + imaginary * imaginary)))
}

@_transparent
public var angle: Scalar {
return Scalar(atan2(Float80(imaginary), Float80(real)))
return Scalar(atan2(LargestFloatType(imaginary), LargestFloatType(real)))
}

//
Expand Down Expand Up @@ -281,7 +292,7 @@ extension Complex where Scalar: BinaryFloatingPoint {

@_transparent
public var angle: Scalar {
return Scalar(atan2(Float80(imaginary), Float80(real)))
return Scalar(atan2(LargestFloatType(imaginary), LargestFloatType(real)))
}

@_transparent
Expand Down
26 changes: 26 additions & 0 deletions Sources/Complex/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ public func exp(_ value: Complex<Double>) -> Complex<Double> {
return Complex<Double>(real: exp * cos(value.imaginary), imaginary: exp * sin(value.imaginary))
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func exp(_ value: Complex<Float80>) -> Complex<Float80> {
let exp = Darwin.exp(value.real)
return Complex<Float80>(real: exp * cos(value.imaginary), imaginary: exp * sin(value.imaginary))
}
#endif

//
// log(a + bi) = log(sqrt(a^2 + b^2)) + i * atan(b / a)
Expand All @@ -96,10 +98,12 @@ public func log(_ value: Complex<Double>) -> Complex<Double> {
return Complex<Double>(real: log(value.modulus), imaginary: value.angle)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func log(_ value: Complex<Float80>) -> Complex<Float80> {
return Complex<Float80>(real: log(value.modulus), imaginary: value.angle)
}
#endif

//

Expand All @@ -113,10 +117,12 @@ public func log10(_ value: Complex<Double>) -> Complex<Double> {
return log(value) / log(10.0)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func log10(_ value: Complex<Float80>) -> Complex<Float80> {
return log(value) / log(10.0)
}
#endif

//

Expand All @@ -130,10 +136,12 @@ public func log2(_ value: Complex<Double>) -> Complex<Double> {
return log(value) / log(2.0)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func log2(_ value: Complex<Float80>) -> Complex<Float80> {
return log(value) / log(2.0)
}
#endif

//
// sin(a + bi) = sin(a) * cosh(b) + i * cos(a) * sinh(b)
Expand All @@ -148,10 +156,12 @@ public func sin(_ value: Complex<Double>) -> Complex<Double> {
return Complex<Double>(real: sin(value.real) * cosh(value.imaginary), imaginary: cos(value.real) * sinh(value.imaginary))
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func sin(_ value: Complex<Float80>) -> Complex<Float80> {
return Complex<Float80>(real: sin(value.real) * cosh(value.imaginary), imaginary: cos(value.real) * sinh(value.imaginary))
}
#endif

//
// asin(z) = -i * ln(iz + sqrt(1 - z^2))
Expand All @@ -176,6 +186,7 @@ public func asin(_ value: Complex<Double>) -> Complex<Double> {
//swiftlint:enable identifier_name
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func asin(_ value: Complex<Float80>) -> Complex<Float80> {
//swiftlint:disable identifier_name
Expand All @@ -185,6 +196,7 @@ public func asin(_ value: Complex<Float80>) -> Complex<Float80> {
return -.i * log(iz + root)
//swiftlint:enable identifier_name
}
#endif

//
// sinh(z) = -i * sin(iz)
Expand All @@ -199,10 +211,12 @@ public func sinh(_ value: Complex<Double>) -> Complex<Double> {
return -.i * sin(.i * value)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func sinh(_ value: Complex<Float80>) -> Complex<Float80> {
return -.i * sin(.i * value)
}
#endif

//
// cos(a + bi) = cos(a) * cosh(b) - i * sin(a) * sinh(b)
Expand All @@ -217,10 +231,12 @@ public func cos(_ value: Complex<Double>) -> Complex<Double> {
return Complex<Double>(real: cos(value.real) * cosh(value.imaginary), imaginary: -sin(value.real) * sinh(value.imaginary))
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func cos(_ value: Complex<Float80>) -> Complex<Float80> {
return Complex<Float80>(real: cos(value.real) * cosh(value.imaginary), imaginary: -sin(value.real) * sinh(value.imaginary))
}
#endif

//
// acos(z) = -i * ln(z + sqrt(z^2 - 1))
Expand All @@ -237,11 +253,13 @@ public func acos(_ value: Complex<Double>) -> Complex<Double> {
return -.i * log(value + root)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func acos(_ value: Complex<Float80>) -> Complex<Float80> {
let root = sqrt((value * value) - 1.0)
return -.i * log(value + root)
}
#endif

//
// cosh(z) = cos(iz)
Expand All @@ -256,10 +274,12 @@ public func cosh(_ value: Complex<Double>) -> Complex<Double> {
return cos(.i * value)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func cosh(_ value: Complex<Float80>) -> Complex<Float80> {
return cos(.i * value)
}
#endif

//

Expand All @@ -273,10 +293,12 @@ public func tan(_ value: Complex<Double>) -> Complex<Double> {
return sin(value) / cos(value)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func tan(_ value: Complex<Float80>) -> Complex<Float80> {
return sin(value) / cos(value)
}
#endif

//
// atan(z) = (i / 2) * ln((i + z) / (i - z))
Expand All @@ -293,11 +315,13 @@ public func atan(_ value: Complex<Double>) -> Complex<Double> {
return .i * 0.5 * log(quotient)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func atan(_ value: Complex<Float80>) -> Complex<Float80> {
let quotient = (.i + value) / (.i - value)
return .i * 0.5 * log(quotient)
}
#endif

//
// tanh(z) = -i * tan(iz)
Expand All @@ -312,9 +336,11 @@ public func tanh(_ value: Complex<Double>) -> Complex<Double> {
return -.i * tan(.i * value)
}

#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
@_transparent
public func tanh(_ value: Complex<Float80>) -> Complex<Float80> {
return -.i * tan(.i * value)
}
#endif

//
Loading

0 comments on commit a6b929e

Please sign in to comment.