2014-06-22 3 views

답변

101

그것은 모두 FloatDouble 유형에 개정하여 FloatingPointNumber 프로토콜에 정의처럼 사람들이 잘못 삭제해야합니다. 사용법은 다음과 같습니다.

let d = 3.0 
let isNan = d.isNaN // False 

let d = Double.NaN 
let isNan = d.isNaN // True 

직접 확인하는 방법을 찾고 있다면 가능합니다. IEEE는 NaN! = NaN을 정의합니다. 즉, NaN을 숫자와 직접 비교할 수 없으므로 숫자가 아닌 것입니다. 그러나 maybeNaN != maybeNaN을 확인할 수 있습니다. 이 조건이 true로 평가되면 NaN을 처리하게됩니다.

aVariable.isNaN을 사용하여 값이 NaN인지 확인해야합니다. 당신은 당신이 작업중인 값의 분류에 대해 덜 확신하는 경우 보조 노트의 조금으로


는, 당신은 당신의 FloatingPointNumber 부합하는 유형의 floatingPointClass 재산의 가치를 전환 할 수 있습니다.

let noClueWhatThisIs: Double = // ... 

switch noClueWhatThisIs.floatingPointClass { 
case .SignalingNaN: 
    print(FloatingPointClassification.SignalingNaN) 
case .QuietNaN: 
    print(FloatingPointClassification.QuietNaN) 
case .NegativeInfinity: 
    print(FloatingPointClassification.NegativeInfinity) 
case .NegativeNormal: 
    print(FloatingPointClassification.NegativeNormal) 
case .NegativeSubnormal: 
    print(FloatingPointClassification.NegativeSubnormal) 
case .NegativeZero: 
    print(FloatingPointClassification.NegativeZero) 
case .PositiveZero: 
    print(FloatingPointClassification.PositiveZero) 
case .PositiveSubnormal: 
    print(FloatingPointClassification.PositiveSubnormal) 
case .PositiveNormal: 
    print(FloatingPointClassification.PositiveNormal) 
case .PositiveInfinity: 
    print(FloatingPointClassification.PositiveInfinity) 
} 

해당 값은 FloatingPointClassification 열거 형으로 선언됩니다.

관련 문제