@@ -138,21 +138,25 @@ public func _float16ToStringImpl(
138
138
_ value: Float16 ,
139
139
_ debug: Bool
140
140
) -> 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 ( )
154
159
}
155
- return UInt64 ( truncatingIfNeeded: textLength)
156
160
}
157
161
158
162
// Convert a Float16 to an optimal ASCII representation.
0 commit comments