Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/JSONAST/JSON.Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ extension JSON.Node {
/// - Returns:
/// The closest value of ``Float16`` to the payload of this variant if it matches
/// ``number(_:) [case]``, `nil` otherwise.
#if arch(arm64)
@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
public func `as`(_: Float16.Type) -> Float16? {
self.as(JSON.Number.self)?.as(Float16.self)
}
#endif

/// Attempts to load an instance of ``Number`` from this variant.
///
Expand Down
2 changes: 2 additions & 0 deletions Sources/JSONAST/JSON.Number.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ extension JSON.Number {

/// Converts this numeric literal to a ``Float16`` value, or its closest
/// floating-point representation.
#if arch(arm64)
@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
public func `as`(_: Float16.Type) -> Float16? {
self.parsed(as: Float16.self)
}
#endif
}
extension JSON.Number {
/// We want floating point types to roundtrip losslessly, the only way to guarantee that is
Expand Down
2 changes: 2 additions & 0 deletions Sources/JSONDecoding/Conformances/Float16 (ext).swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#if arch(arm64)
@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
extension Float16: JSONDecodable {
@inlinable public init(json: borrowing JSON.Node) throws {
self = try json.cast { $0.as(Self.self) }
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/JSONEncoding/Conformances/Float16 (ext).swift
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#if arch(arm64)
@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
extension Float16: JSONEncodable {}
#endif
Loading