Skip to content

Commit 2d291b8

Browse files
Merge pull request #8 from SomeRandomiOSDev/1.1.0_OverflowingFunctions
Added additional overflowing functions for multiplying and dividing
2 parents 53adbb5 + 9edf42b commit 2d291b8

File tree

7 files changed

+1930
-361
lines changed

7 files changed

+1930
-361
lines changed

Complex.xcodeproj/project.pbxproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
/* End PBXAggregateTarget section */
3333

3434
/* Begin PBXBuildFile section */
35+
DD6F08BE24001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08BD24001B9A00749359 /* ComplexOverflowingArithmetic.swift */; };
36+
DD6F08BF24001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08BD24001B9A00749359 /* ComplexOverflowingArithmetic.swift */; };
37+
DD6F08C024001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08BD24001B9A00749359 /* ComplexOverflowingArithmetic.swift */; };
38+
DD6F08C124001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08BD24001B9A00749359 /* ComplexOverflowingArithmetic.swift */; };
39+
DD6F08C324001CD400749359 /* ComplexOverflowingArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08C224001CD400749359 /* ComplexOverflowingArithmeticTests.swift */; };
40+
DD6F08C424001CD400749359 /* ComplexOverflowingArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08C224001CD400749359 /* ComplexOverflowingArithmeticTests.swift */; };
41+
DD6F08C524001CD400749359 /* ComplexOverflowingArithmeticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08C224001CD400749359 /* ComplexOverflowingArithmeticTests.swift */; };
3542
DD6F08CD240077C300749359 /* TestingBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08CC240077C300749359 /* TestingBase.swift */; };
3643
DD6F08CE240077C300749359 /* TestingBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08CC240077C300749359 /* TestingBase.swift */; };
3744
DD6F08CF240077C300749359 /* TestingBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6F08CC240077C300749359 /* TestingBase.swift */; };
@@ -149,6 +156,8 @@
149156
/* End PBXContainerItemProxy section */
150157

151158
/* Begin PBXFileReference section */
159+
DD6F08BD24001B9A00749359 /* ComplexOverflowingArithmetic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComplexOverflowingArithmetic.swift; sourceTree = "<group>"; };
160+
DD6F08C224001CD400749359 /* ComplexOverflowingArithmeticTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComplexOverflowingArithmeticTests.swift; sourceTree = "<group>"; };
152161
DD6F08CC240077C300749359 /* TestingBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingBase.swift; sourceTree = "<group>"; };
153162
DD6F08D02400808300749359 /* codecov.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = codecov.yml; sourceTree = "<group>"; };
154163
DDB8120623F59B760079FEB5 /* Complex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Complex.swift; sourceTree = "<group>"; };
@@ -310,6 +319,7 @@
310319
DD6F08CC240077C300749359 /* TestingBase.swift */,
311320
DDB8121023F5AEB10079FEB5 /* ComplexTests.swift */,
312321
DDB8126623F7B7F40079FEB5 /* ComplexArithmeticTests.swift */,
322+
DD6F08C224001CD400749359 /* ComplexOverflowingArithmeticTests.swift */,
313323
DDB8122023F656AC0079FEB5 /* FunctionsTests.swift */,
314324
DDB8128523FB1A430079FEB5 /* FunctionsTests.swift.gyb */,
315325
DDFEEC4323EF13910096015C /* ComplexTests-Info.plist */,
@@ -347,8 +357,9 @@
347357
children = (
348358
DDB8120623F59B760079FEB5 /* Complex.swift */,
349359
DDB8126123F7B1C90079FEB5 /* ComplexArithmetic.swift */,
350-
DDB8126F23FA2C210079FEB5 /* Functions.swift.gyb */,
360+
DD6F08BD24001B9A00749359 /* ComplexOverflowingArithmetic.swift */,
351361
DDB8120B23F5A8E80079FEB5 /* Functions.swift */,
362+
DDB8126F23FA2C210079FEB5 /* Functions.swift.gyb */,
352363
DDB8125823F707EE0079FEB5 /* Operators.swift */,
353364
);
354365
path = Complex;
@@ -698,6 +709,7 @@
698709
DDB8125923F707EE0079FEB5 /* Operators.swift in Sources */,
699710
DDB8120723F59B760079FEB5 /* Complex.swift in Sources */,
700711
DDB8120C23F5A8E80079FEB5 /* Functions.swift in Sources */,
712+
DD6F08BE24001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */,
701713
);
702714
runOnlyForDeploymentPostprocessing = 0;
703715
};
@@ -707,6 +719,7 @@
707719
files = (
708720
DDB8126723F7B7F40079FEB5 /* ComplexArithmeticTests.swift in Sources */,
709721
DD6F08CD240077C300749359 /* TestingBase.swift in Sources */,
722+
DD6F08C324001CD400749359 /* ComplexOverflowingArithmeticTests.swift in Sources */,
710723
DDB8121123F5AEB10079FEB5 /* ComplexTests.swift in Sources */,
711724
DDB8122123F656AC0079FEB5 /* FunctionsTests.swift in Sources */,
712725
);
@@ -720,6 +733,7 @@
720733
DDB8125A23F707EE0079FEB5 /* Operators.swift in Sources */,
721734
DDB8120823F59B760079FEB5 /* Complex.swift in Sources */,
722735
DDB8120D23F5A8E80079FEB5 /* Functions.swift in Sources */,
736+
DD6F08BF24001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */,
723737
);
724738
runOnlyForDeploymentPostprocessing = 0;
725739
};
@@ -729,6 +743,7 @@
729743
files = (
730744
DDB8126823F7B7F40079FEB5 /* ComplexArithmeticTests.swift in Sources */,
731745
DD6F08CE240077C300749359 /* TestingBase.swift in Sources */,
746+
DD6F08C424001CD400749359 /* ComplexOverflowingArithmeticTests.swift in Sources */,
732747
DDB8121223F5AEB10079FEB5 /* ComplexTests.swift in Sources */,
733748
DDB8122223F656AC0079FEB5 /* FunctionsTests.swift in Sources */,
734749
);
@@ -742,6 +757,7 @@
742757
DDB8125B23F707EE0079FEB5 /* Operators.swift in Sources */,
743758
DDB8120923F59B760079FEB5 /* Complex.swift in Sources */,
744759
DDB8120E23F5A8E80079FEB5 /* Functions.swift in Sources */,
760+
DD6F08C024001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */,
745761
);
746762
runOnlyForDeploymentPostprocessing = 0;
747763
};
@@ -751,6 +767,7 @@
751767
files = (
752768
DDB8126923F7B7F40079FEB5 /* ComplexArithmeticTests.swift in Sources */,
753769
DD6F08CF240077C300749359 /* TestingBase.swift in Sources */,
770+
DD6F08C524001CD400749359 /* ComplexOverflowingArithmeticTests.swift in Sources */,
754771
DDB8121323F5AEB10079FEB5 /* ComplexTests.swift in Sources */,
755772
DDB8122323F656AC0079FEB5 /* FunctionsTests.swift in Sources */,
756773
);
@@ -764,6 +781,7 @@
764781
DDB8125C23F707EE0079FEB5 /* Operators.swift in Sources */,
765782
DDB8120A23F59B760079FEB5 /* Complex.swift in Sources */,
766783
DDB8120F23F5A8E80079FEB5 /* Functions.swift in Sources */,
784+
DD6F08C124001B9A00749359 /* ComplexOverflowingArithmetic.swift in Sources */,
767785
);
768786
runOnlyForDeploymentPostprocessing = 0;
769787
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Complex
66
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
77
[![Platform](https://img.shields.io/cocoapods/p/Complex.svg)](https://cocoapods.org/pods/Complex)
88
[![Build](https://travis-ci.com/SomeRandomiOSDev/Complex.svg?branch=master)](https://travis-ci.com/SomeRandomiOSDev/Complex)
9+
![Swift](https://github.com/SomeRandomiOSDev/Complex/workflows/Swift/badge.svg)
910
[![Code Coverage](https://codecov.io/gh/SomeRandomiOSDev/Complex/branch/master/graph/badge.svg)](https://codecov.io/gh/SomeRandomiOSDev/Complex)
1011
[![Codacy](https://api.codacy.com/project/badge/Grade/8ad52c117e4a46d9aa4699d22fc0bf49)](https://app.codacy.com/app/SomeRandomiOSDev/Complex?utm_source=github.com&utm_medium=referral&utm_content=SomeRandomiOSDev/Complex&utm_campaign=Badge_Grade_Dashboard)
1112

Sources/Complex/ComplexArithmetic.swift

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,6 @@ extension Complex where Scalar: FixedWidthInteger {
184184
}
185185
}
186186

187-
extension Complex where Scalar: FixedWidthInteger {
188-
189-
@_transparent
190-
public func addingReportingOverflow(_ rhs: Complex<Scalar>) -> (partialValue: Complex<Scalar>, overflow: Bool) {
191-
let real = self.real.addingReportingOverflow(rhs.real)
192-
let imaginary = self.imaginary.addingReportingOverflow(rhs.imaginary)
193-
let overflow = real.overflow || imaginary.overflow
194-
195-
return (partialValue: Complex<Scalar>(real: real.partialValue, imaginary: imaginary.partialValue), overflow: overflow)
196-
}
197-
198-
@_transparent
199-
public func subtractingReportingOverflow(_ rhs: Complex<Scalar>) -> (partialValue: Complex<Scalar>, overflow: Bool) {
200-
let real = self.real.subtractingReportingOverflow(rhs.real)
201-
let imaginary = self.imaginary.subtractingReportingOverflow(rhs.imaginary)
202-
let overflow = real.overflow || imaginary.overflow
203-
204-
return (partialValue: Complex<Scalar>(real: real.partialValue, imaginary: imaginary.partialValue), overflow: overflow)
205-
}
206-
}
207-
208187
// MARK: - Multiplication
209188

210189
extension Complex {
@@ -297,25 +276,6 @@ extension Complex where Scalar: FixedWidthInteger {
297276
}
298277
}
299278

300-
extension Complex where Scalar: FixedWidthInteger {
301-
302-
@_transparent
303-
public func componentwiseMultipliedFullWidth(by rhs: Complex<Scalar>) -> (high: Complex<Scalar>, low: Complex<Scalar.Magnitude>) {
304-
let real = self.real.multipliedFullWidth(by: rhs.real)
305-
let imaginary = self.imaginary.multipliedFullWidth(by: rhs.imaginary)
306-
307-
return (high: Complex<Scalar>(real: real.high, imaginary: imaginary.high), low: Complex<Scalar.Magnitude>(real: real.low, imaginary: imaginary.low))
308-
}
309-
310-
@_transparent
311-
public func componentwiseMultipliedReportingOverflow(by rhs: Complex<Scalar>) -> (partialValue: Complex<Scalar>, overflow: Bool) {
312-
let real = self.real.multipliedReportingOverflow(by: rhs.real)
313-
let imaginary = self.imaginary.multipliedReportingOverflow(by: rhs.imaginary)
314-
315-
return (partialValue: Complex<Scalar>(real: real.partialValue, imaginary: imaginary.partialValue), overflow: real.overflow || imaginary.overflow)
316-
}
317-
}
318-
319279
// MARK: - Division (BinaryInteger)
320280

321281
extension Complex where Scalar: BinaryInteger {
@@ -415,22 +375,3 @@ extension Complex where Scalar: FloatingPoint {
415375
lhs = lhs ./ rhs
416376
}
417377
}
418-
419-
extension Complex where Scalar: FixedWidthInteger {
420-
421-
@_transparent
422-
public func componentwiseDividedReportingOverflow(by rhs: Complex<Scalar>) -> (partialValue: Complex<Scalar>, overflow: Bool) {
423-
let real = self.real.dividedReportingOverflow(by: rhs.real)
424-
let imaginary = self.imaginary.dividedReportingOverflow(by: rhs.imaginary)
425-
426-
return (partialValue: Complex<Scalar>(real: real.partialValue, imaginary: imaginary.partialValue), overflow: real.overflow || imaginary.overflow)
427-
}
428-
429-
@_transparent
430-
public func componentwiseDividingFullWidth(_ dividend: (high: Complex<Scalar>, low: Complex<Scalar.Magnitude>)) -> (quotient: Complex<Scalar>, remainder: Complex<Scalar>) {
431-
let real = self.real.dividingFullWidth((high: dividend.high.real, low: dividend.low.real))
432-
let imaginary = self.imaginary.dividingFullWidth((high: dividend.high.imaginary, low: dividend.low.imaginary))
433-
434-
return (quotient: Complex<Scalar>(real: real.quotient, imaginary: imaginary.quotient), remainder: Complex<Scalar>(real: real.remainder, imaginary: imaginary.remainder))
435-
}
436-
}

0 commit comments

Comments
 (0)