From 01b3475c80c789a00d4203caad1d401afd7ee8f5 Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Sun, 4 Oct 2020 20:23:46 -0700 Subject: [PATCH] Removed Float80 from ARM64 targets --- .../Swift Extensions/FloatingPoint.swift | 25 ++++++------ .../OTCore/Swift Extensions/Integers.swift | 7 ++-- .../Swift Extensions/NSAttributedString.swift | 4 ++ Sources/OTCore/Swift Extensions/URL.swift | 2 +- .../FloatingPoint Tests.swift | 26 +++++++++++- .../Swift Extensions/Integers Tests.swift | 40 ++++++++++++++----- .../Swift Extensions/Operators Tests.swift | 3 ++ 7 files changed, 79 insertions(+), 28 deletions(-) diff --git a/Sources/OTCore/Swift Extensions/FloatingPoint.swift b/Sources/OTCore/Swift Extensions/FloatingPoint.swift index 6306984..fc29f07 100644 --- a/Sources/OTCore/Swift Extensions/FloatingPoint.swift +++ b/Sources/OTCore/Swift Extensions/FloatingPoint.swift @@ -149,15 +149,15 @@ extension Float: FloatingPointPower { } } -// Float80 seems to be deprecated as of the introduction of ARM64 - -//extension Float80: FloatingPointPower { -// /// OTCore: -// /// Convenience method for pow() -// public func power(_ exponent: Float80) -> Float80 { -// powl(self, exponent) -// } -//} +#if !arch(arm64) // Float80 is removed for ARM64 +extension Float80: FloatingPointPower { + /// OTCore: + /// Convenience method for pow() + public func power(_ exponent: Float80) -> Float80 { + powl(self, exponent) + } +} +#endif extension CGFloat: FloatingPointPower { /// OTCore: @@ -325,9 +325,10 @@ extension StringProtocol { /// OTCore: Convenience method to return a Float public var float: Float? { Float(self) } - // Float80 is removed for ARM64 - // /// OTCore: Convenience method to return a Float80 - // public var float80: Float80? { Float80(self) } + #if !arch(arm64) // Float80 is removed for ARM64 + /// OTCore: Convenience method to return a Float80 + public var float80: Float80? { Float80(self) } + #endif /// OTCore: Convenience method to return a Decimal public var decimal: Decimal? { Decimal(string: String(self)) } diff --git a/Sources/OTCore/Swift Extensions/Integers.swift b/Sources/OTCore/Swift Extensions/Integers.swift index c433a26..8b739aa 100644 --- a/Sources/OTCore/Swift Extensions/Integers.swift +++ b/Sources/OTCore/Swift Extensions/Integers.swift @@ -56,9 +56,10 @@ extension BinaryInteger { /// OTCore: Convenience method to return a Float32 public var float32: Float32 { return Float32(self) } - // Float80 is removed for ARM64 - // /// OTCore: Convenience method to return a Float80 - // public var float80: Float80 { return Float80(self) } + #if !arch(arm64) // Float80 is removed for ARM64 + /// OTCore: Convenience method to return a Float80 + public var float80: Float80 { return Float80(self) } + #endif /// OTCore: Convenience method to return a CGFloat public var cgFloat: CGFloat { return CGFloat(self) } diff --git a/Sources/OTCore/Swift Extensions/NSAttributedString.swift b/Sources/OTCore/Swift Extensions/NSAttributedString.swift index cc3c077..e6dd83c 100644 --- a/Sources/OTCore/Swift Extensions/NSAttributedString.swift +++ b/Sources/OTCore/Swift Extensions/NSAttributedString.swift @@ -6,7 +6,11 @@ // Copyright © 2020 Steffan Andrews. All rights reserved. // +#if os(macOS) import Cocoa +#else +import UIKit +#endif extension NSAttributedString { diff --git a/Sources/OTCore/Swift Extensions/URL.swift b/Sources/OTCore/Swift Extensions/URL.swift index 3854eea..d01dfee 100644 --- a/Sources/OTCore/Swift Extensions/URL.swift +++ b/Sources/OTCore/Swift Extensions/URL.swift @@ -199,7 +199,7 @@ extension FileManager { /// Backwards compatible method for retrieving a temporary folder from the system. public static var temporaryDirectoryCompat: URL { - if #available(OSX 10.12, *) { + if #available(OSX 10.12, iOS 10.0, *) { return FileManager.default.temporaryDirectory } else { return URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) diff --git a/Tests/OTCoreTests/Swift Extensions/FloatingPoint Tests.swift b/Tests/OTCoreTests/Swift Extensions/FloatingPoint Tests.swift index 2334b22..015d12f 100644 --- a/Tests/OTCoreTests/Swift Extensions/FloatingPoint Tests.swift +++ b/Tests/OTCoreTests/Swift Extensions/FloatingPoint Tests.swift @@ -76,6 +76,8 @@ class Extensions_FloatingPoint_Tests: XCTestCase { // Float80 + #if !arch(arm64) // Float80 is removed for ARM64 + let float80 = Float80(123.456) _ = float80.int @@ -103,6 +105,8 @@ class Extensions_FloatingPoint_Tests: XCTestCase { _ = float80.uint64 _ = float80.uint64Exactly + #endif + // CGFloat let cgfloat = CGFloat(123.456) @@ -153,7 +157,11 @@ class Extensions_FloatingPoint_Tests: XCTestCase { var b: Bool = false b = 0.0.boolValue b = Float(1).boolValue + + #if !arch(arm64) // Float80 is removed for ARM64 b = Float80(1).boolValue + #endif + b = CGFloat(1).boolValue b = Decimal(1).boolValue _ = b // silences 'variable was written to, but never read' warning @@ -169,7 +177,9 @@ class Extensions_FloatingPoint_Tests: XCTestCase { XCTAssertEqual( 2.0.power(3) , 8.0) // Double XCTAssertEqual( Float(2.0).power(3) , 8.0) - //XCTAssertEqual(Float80(2.0).power(3) , 8.0) + #if !arch(arm64) // Float80 is removed for ARM64 + XCTAssertEqual(Float80(2.0).power(3) , 8.0) + #endif XCTAssertEqual(CGFloat(2.0).power(3) , 8.0) XCTAssertEqual(Decimal(2.0).power(3) , 8.0) @@ -296,13 +306,21 @@ class Extensions_FloatingPoint_Tests: XCTestCase { var str: String = "" str = 0.0.string str = Float(1).string + + #if !arch(arm64) // Float80 is removed for ARM64 str = Float80(1).string + #endif + str = CGFloat(1).string str = Decimal(1).string _ = str // silences 'variable was written to, but never read' warning XCTAssertEqual( Float(1).string, "1.0") + + #if !arch(arm64) // Float80 is removed for ARM64 XCTAssertEqual(Float80(1).string, "1.0") + #endif + XCTAssertEqual(CGFloat(1).string, "1.0") XCTAssertEqual(Decimal(1).string, "1") @@ -312,7 +330,11 @@ class Extensions_FloatingPoint_Tests: XCTestCase { XCTAssertEqual("1.0".double, 1.0) XCTAssertEqual("1.0".float, 1.0) - //XCTAssertEqual("1.0".float80, 1.0) + + #if !arch(arm64) // Float80 is removed for ARM64 + XCTAssertEqual("1.0".float80, 1.0) + #endif + XCTAssertEqual("1.0".decimal, 1.0) } diff --git a/Tests/OTCoreTests/Swift Extensions/Integers Tests.swift b/Tests/OTCoreTests/Swift Extensions/Integers Tests.swift index 8990b34..4bde68b 100644 --- a/Tests/OTCoreTests/Swift Extensions/Integers Tests.swift +++ b/Tests/OTCoreTests/Swift Extensions/Integers Tests.swift @@ -32,7 +32,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = 1.double _ = 1.float _ = 1.float32 - //_ = 1.float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = 1.float80 + #endif _ = 1.cgFloat _ = 1.decimal @@ -52,7 +54,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = UInt(1).double _ = UInt(1).float _ = UInt(1).float32 - //_ = UInt(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = UInt(1).float80 + #endif _ = UInt(1).cgFloat _ = UInt(1).decimal @@ -72,7 +76,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = Int8(1).double _ = Int8(1).float _ = Int8(1).float32 - //_ = Int8(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = Int8(1).float80 + #endif _ = Int8(1).cgFloat _ = Int8(1).decimal @@ -92,7 +98,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = UInt8(1).double _ = UInt8(1).float _ = UInt8(1).float32 - //_ = UInt8(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = UInt8(1).float80 + #endif _ = UInt8(1).cgFloat _ = UInt8(1).decimal @@ -112,7 +120,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = Int16(1).double _ = Int16(1).float _ = Int16(1).float32 - //_ = Int16(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = Int16(1).float80 + #endif _ = Int16(1).cgFloat _ = Int16(1).decimal @@ -132,7 +142,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = UInt16(1).double _ = UInt16(1).float _ = UInt16(1).float32 - //_ = UInt16(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = UInt16(1).float80 + #endif _ = UInt16(1).cgFloat _ = UInt16(1).decimal @@ -152,7 +164,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = Int32(1).double _ = Int32(1).float _ = Int32(1).float32 - //_ = Int32(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = Int32(1).float80 + #endif _ = Int32(1).cgFloat _ = Int32(1).decimal @@ -172,7 +186,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = UInt32(1).double _ = UInt32(1).float _ = UInt32(1).float32 - //_ = UInt32(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = UInt32(1).float80 + #endif _ = UInt32(1).cgFloat _ = UInt32(1).decimal @@ -192,7 +208,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = Int64(1).double _ = Int64(1).float _ = Int64(1).float32 - //_ = Int64(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = Int64(1).float80 + #endif _ = Int64(1).cgFloat _ = Int64(1).decimal @@ -212,7 +230,9 @@ class Extensions_Integers_Tests: XCTestCase { _ = UInt64(1).double _ = UInt64(1).float _ = UInt64(1).float32 - //_ = UInt64(1).float80 + #if !arch(arm64) // Float80 is removed for ARM64 + _ = UInt64(1).float80 + #endif _ = UInt64(1).cgFloat _ = UInt64(1).decimal diff --git a/Tests/OTCoreTests/Swift Extensions/Operators Tests.swift b/Tests/OTCoreTests/Swift Extensions/Operators Tests.swift index 97244fc..cd40d8b 100644 --- a/Tests/OTCoreTests/Swift Extensions/Operators Tests.swift +++ b/Tests/OTCoreTests/Swift Extensions/Operators Tests.swift @@ -20,7 +20,10 @@ class Extensions_Operators_Tests: XCTestCase { XCTAssertEqual( 43.0 % 10.0, 3.0) XCTAssertEqual( Float(43.0) % 10.0, 3.0) + + #if !arch(arm64) XCTAssertEqual(Float80(43.0) % 10.0, 3.0) + #endif // CGFloat