Skip to content

Commit 7a4bd46

Browse files
committed
Adjust availability checks for float16
1 parent a337e72 commit 7a4bd46

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

stdlib/public/core/FloatingPointToString.swift

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,25 @@ public func _float16ToStringImpl(
138138
_ value: Float16,
139139
_ debug: Bool
140140
) -> UInt64 {
141-
// Code below works with raw memory.
142-
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
143-
_unchecked: textBuffer,
144-
count: Int(bufferLength))
145-
let textRange = _Float16ToASCII(value: value, buffer: &buffer)
146-
let textLength = textRange.upperBound - textRange.lowerBound
147-
148-
// Move the text to the start of the buffer
149-
if textRange.lowerBound != 0 {
150-
unsafe _memmove(
151-
dest: textBuffer,
152-
src: textBuffer + textRange.lowerBound,
153-
size: UInt(truncatingIfNeeded: textLength))
141+
if #available(SwiftStdlib 6.2, *) {
142+
// Code below works with raw memory.
143+
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
144+
_unchecked: textBuffer,
145+
count: Int(bufferLength))
146+
let textRange = _Float16ToASCII(value: value, buffer: &buffer)
147+
let textLength = textRange.upperBound - textRange.lowerBound
148+
149+
// Move the text to the start of the buffer
150+
if textRange.lowerBound != 0 {
151+
unsafe _memmove(
152+
dest: textBuffer,
153+
src: textBuffer + textRange.lowerBound,
154+
size: UInt(truncatingIfNeeded: textLength))
155+
}
156+
return UInt64(truncatingIfNeeded: textLength)
157+
} else {
158+
fatalError()
154159
}
155-
return UInt64(truncatingIfNeeded: textLength)
156160
}
157161

158162
// Convert a Float16 to an optimal ASCII representation.

0 commit comments

Comments
 (0)