@@ -224,37 +224,12 @@ internal protocol _IntegerLike : Integer, _BitShiftable {
224
224
static var min : Self { get }
225
225
}
226
226
227
- internal protocol _FloatArithmeticType {
228
- static func + ( lhs: Self , rhs: Self ) -> Self
229
- static func - ( lhs: Self , rhs: Self ) -> Self
230
- static func * ( lhs: Self , rhs: Self ) -> Self
231
- static func / ( lhs: Self , rhs: Self ) -> Self
232
- }
233
-
234
- internal protocol _FloatLike : FloatingPoint , _FloatArithmeticType {
235
- init ( _ value: Int )
236
- init ( _ value: Double )
237
- static var max : Self { get }
238
- static var min : Self { get }
239
- }
240
-
241
227
extension Int : _IntegerLike { }
242
228
extension Int32 : _IntegerLike { }
243
229
extension Int64 : _IntegerLike { }
244
230
extension UInt32 : _IntegerLike { }
245
231
extension UInt64 : _IntegerLike { }
246
232
247
- // these might be good to have in the stdlib
248
- extension Float : _FloatLike {
249
- static var max : Float { return FLT_MAX }
250
- static var min : Float { return FLT_MIN }
251
- }
252
-
253
- extension Double : _FloatLike {
254
- static var max : Double { return DBL_MAX }
255
- static var min : Double { return DBL_MIN }
256
- }
257
-
258
233
private func numericValue( _ ch: unichar ) -> Int {
259
234
if ( ch >= unichar ( unicodeScalarLiteral: " 0 " ) && ch <= unichar ( unicodeScalarLiteral: " 9 " ) ) {
260
235
return Int ( ch) - Int( unichar ( unicodeScalarLiteral: " 0 " ) )
@@ -366,7 +341,7 @@ extension String {
366
341
return true
367
342
}
368
343
369
- internal func scan< T: _FloatLike > ( _ skipSet: CharacterSet ? , locale: Locale ? , locationToScanFrom: inout Int , to: ( T ) -> Void ) -> Bool {
344
+ internal func scan< T: BinaryFloatingPoint > ( _ skipSet: CharacterSet ? , locale: Locale ? , locationToScanFrom: inout Int , to: ( T ) -> Void ) -> Bool {
370
345
let ds_chars = decimalSep ( locale) . utf16
371
346
let ds = ds_chars [ ds_chars. startIndex]
372
347
var buf = _NSStringBuffer ( string: self , start: locationToScanFrom, end: length)
@@ -388,13 +363,13 @@ extension String {
388
363
if numeral == - 1 {
389
364
break
390
365
}
391
- // if (localResult >= T.max / T(10)) && ((localResult > T.max / T(10)) || T(numericValue(buf.currentCharacter) - (neg ? 1 : 0)) >= T.max - localResult * T(10)) is evidently too complex; so break it down to more "edible chunks"
392
- let limit1 = localResult >= T . max / T( 10 )
393
- let limit2 = localResult > T . max / T( 10 )
394
- let limit3 = T ( numeral - ( neg ? 1 : 0 ) ) >= T . max - localResult * T( 10 )
366
+ // if (localResult >= T.greatestFiniteMagnitude / T(10)) && ((localResult > T.greatestFiniteMagnitude / T(10)) || T(numericValue(buf.currentCharacter) - (neg ? 1 : 0)) >= T.greatestFiniteMagnitude - localResult * T(10)) is evidently too complex; so break it down to more "edible chunks"
367
+ let limit1 = localResult >= T . greatestFiniteMagnitude / T( 10 )
368
+ let limit2 = localResult > T . greatestFiniteMagnitude / T( 10 )
369
+ let limit3 = T ( numeral - ( neg ? 1 : 0 ) ) >= T . greatestFiniteMagnitude - localResult * T( 10 )
395
370
if ( limit1) && ( limit2 || limit3) {
396
371
// apply the clamps and advance past the ending of the buffer where there are still digits
397
- localResult = neg ? T . min : T . max
372
+ localResult = neg ? - T . infinity : T . infinity
398
373
neg = false
399
374
repeat {
400
375
buf. advance ( )
@@ -425,7 +400,7 @@ extension String {
425
400
return true
426
401
}
427
402
428
- internal func scanHex< T: _FloatLike > ( _ skipSet: CharacterSet ? , locale: Locale ? , locationToScanFrom: inout Int , to: ( T ) -> Void ) -> Bool {
403
+ internal func scanHex< T: BinaryFloatingPoint > ( _ skipSet: CharacterSet ? , locale: Locale ? , locationToScanFrom: inout Int , to: ( T ) -> Void ) -> Bool {
429
404
NSUnimplemented ( )
430
405
}
431
406
}
0 commit comments