Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了可可 – 这是Swift等价的isnan()?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

这是相当于isnan()在Swift? 我需要检查一些操作结果是否有效,并删除那些无效像x / 0 谢谢 它在 FloaTingPointnumber协议中定义, Float和 Double类型都符合。用法如下: let d = 3.0 let isNan = d.isNaN // false let d = Double.NaN let isNan = d.isNaN // True 如果你正
这是相当于isnan()在Swift?
我需要检查一些操作结果是否有效,并删除那些无效像x / 0
谢谢
它在 FloatingPointNumber协议中定义, FloatDouble类型都符合。用法如下:
let d = 3.0
let isNan = d.isNaN // false

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

如果你正在寻找一种方法来自己做这个检查,你可以。 IEEE定义NaN!= NaN,意味着你不能直接比较NaN和一个数字来确定它的数字。但是,你可以检查maybeNaN!= maybeNaN。如果这个条件的计算结果为真,那么你正在处理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枚举中声明。

大佬总结

以上是大佬教程为你收集整理的可可 – 这是Swift等价的isnan()?全部内容,希望文章能够帮你解决可可 – 这是Swift等价的isnan()?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。