Skip to content

Commit

Permalink
Merge pull request #29 from crichez/float16-availability-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
crichez authored Feb 4, 2022
2 parents eacd002 + c61e1bb commit e7d8156
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
10 changes: 2 additions & 8 deletions Sources/FowlerNollVo/FNVHashable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ extension Float: FNVHashable {
}
}

#if arch(arm)
@available(macOS 11, *)
@available(macCatalyst 14, *)
@available(macOSApplicationExtension 11, *)
@available(macCatalystApplicationExtension 14, *)
@available(iOS 14, *)
@available(watchOS 7, *)
@available(tvOS 14, *)
#if swift(>=5.4) && !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
@available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)
extension Float16: FNVHashable {
public func hash<Hasher>(into hasher: inout Hasher) where Hasher : FNVHasher {
withUnsafeBytes(of: self) { hasher.combine($0) }
Expand Down
20 changes: 19 additions & 1 deletion Tests/FowlerNollVoTests/HashStabilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class HashStabilityTests: XCTestCase {
}
}

/// An array of randomly generated `FNVHashable` values.
let inputs: [FNVHashable] = [
"this is a test \u{10424}", String?.none,
Bool.random(), Bool?.none,
Expand Down Expand Up @@ -80,4 +79,23 @@ class HashStabilityTests: XCTestCase {
checkStability(of: input, withHasher: FNV1024a.self)
}
}

#if swift(>=5.4) && !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
func testFloat16() {
let input = Float16.random(in: .leastNonzeroMagnitude ... .greatestFiniteMagnitude)
checkStability(of: input, withHasher: FNV32a.self)
checkStability(of: input, withHasher: FNV64.self)
checkStability(of: input, withHasher: FNV64a.self)
checkStability(of: input, withHasher: FNV128.self)
checkStability(of: input, withHasher: FNV128a.self)
checkStability(of: input, withHasher: FNV256.self)
checkStability(of: input, withHasher: FNV256a.self)
checkStability(of: input, withHasher: FNV512.self)
checkStability(of: input, withHasher: FNV512a.self)
checkStability(of: input, withHasher: FNV1024.self)
checkStability(of: input, withHasher: FNV1024a.self)
}
#endif

}

0 comments on commit e7d8156

Please sign in to comment.