From 8781d8e8d7bbcfeb868a17f82a235f083b09b565 Mon Sep 17 00:00:00 2001 From: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> Date: Wed, 15 Oct 2025 22:56:48 -0400 Subject: [PATCH] Conform floating points to `JSONEncodable`. Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> --- .../Encoders/JSON.Literal (ext).swift | 25 +++++++++++++++++++ Sources/JSONEncoding/JSONEncodable.swift | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/Sources/JSONEncoding/Encoders/JSON.Literal (ext).swift b/Sources/JSONEncoding/Encoders/JSON.Literal (ext).swift index 3cdd11f..9e3d794 100644 --- a/Sources/JSONEncoding/Encoders/JSON.Literal (ext).swift +++ b/Sources/JSONEncoding/Encoders/JSON.Literal (ext).swift @@ -28,3 +28,28 @@ extension JSON.Literal where Value:BinaryInteger json.utf8 += self.value.description.utf8 } } +extension JSON.Literal +{ + @inlinable internal static + func += (json:inout JSON, self:Self) + { + json.utf8 += self.value.description.utf8 + } +} +extension JSON.Literal +{ + @inlinable internal static + func += (json:inout JSON, self:Self) + { + json.utf8 += self.value.description.utf8 + } +} +@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) +extension JSON.Literal +{ + @inlinable internal static + func += (json:inout JSON, self:Self) + { + json.utf8 += self.value.description.utf8 + } +} diff --git a/Sources/JSONEncoding/JSONEncodable.swift b/Sources/JSONEncoding/JSONEncodable.swift index f656330..be47ea2 100644 --- a/Sources/JSONEncoding/JSONEncodable.swift +++ b/Sources/JSONEncoding/JSONEncodable.swift @@ -22,6 +22,31 @@ extension JSONEncodable where Self:BinaryInteger json += JSON.Literal.init(self) } } +extension Double:JSONEncodable +{ + @inlinable public + func encode(to json:inout JSON) + { + json += JSON.Literal.init(self) + } +} +extension Float:JSONEncodable +{ + @inlinable public + func encode(to json:inout JSON) + { + json += JSON.Literal.init(self) + } +} +@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) +extension Float16:JSONEncodable +{ + @inlinable public + func encode(to json:inout JSON) + { + json += JSON.Literal.init(self) + } +} extension JSONEncodable where Self:RawRepresentable, RawValue:JSONEncodable { @inlinable public