Skip to content

Commit a6b929e

Browse files
Merge pull request #10 from SomeRandomiOSDev/1.1.1
Release 1.1.1
2 parents 862708b + b8b2ef4 commit a6b929e

File tree

6 files changed

+177
-62
lines changed

6 files changed

+177
-62
lines changed

Complex.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "Complex"
4-
s.version = "1.1.0"
4+
s.version = "1.1.1"
55
s.summary = "Swift Complex Number"
66
s.description = <<-DESC
77
A lightweight framework designed for representing and working with complex numbers for iOS, macOS, tvOS, and watchOS.

Sources/Complex/Complex.swift

+14-3
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,27 @@ extension Complex: Decodable where Scalar: Decodable {
208208

209209
// MARK: - Complex BinaryInteger Extensions
210210

211+
extension Complex {
212+
213+
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
214+
@usableFromInline
215+
internal typealias LargestFloatType = Float80
216+
#else
217+
@usableFromInline
218+
internal typealias LargestFloatType = Double
219+
#endif
220+
}
221+
211222
extension Complex where Scalar: BinaryInteger {
212223

213224
@_transparent
214225
public var modulus: Scalar {
215-
return Scalar(sqrt(Float80(real * real + imaginary * imaginary)))
226+
return Scalar(sqrt(LargestFloatType(real * real + imaginary * imaginary)))
216227
}
217228

218229
@_transparent
219230
public var angle: Scalar {
220-
return Scalar(atan2(Float80(imaginary), Float80(real)))
231+
return Scalar(atan2(LargestFloatType(imaginary), LargestFloatType(real)))
221232
}
222233

223234
//
@@ -281,7 +292,7 @@ extension Complex where Scalar: BinaryFloatingPoint {
281292

282293
@_transparent
283294
public var angle: Scalar {
284-
return Scalar(atan2(Float80(imaginary), Float80(real)))
295+
return Scalar(atan2(LargestFloatType(imaginary), LargestFloatType(real)))
285296
}
286297

287298
@_transparent

Sources/Complex/Functions.swift

+26
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ public func exp(_ value: Complex<Double>) -> Complex<Double> {
7777
return Complex<Double>(real: exp * cos(value.imaginary), imaginary: exp * sin(value.imaginary))
7878
}
7979

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

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

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

104108
//
105109

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

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

121127
//
122128

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

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

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

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

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

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

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

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

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

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

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

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

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

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

264284
//
265285

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

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

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

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

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

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

320346
//

0 commit comments

Comments
 (0)