infix operator ~= : ComparisonPrecedence
func ~=<T> (lhs:T,rhs:T)->Bool where T : FloatingPoint {
return lhs == rhs || lhs.nextDown == rhs || lhs.nextUp == rhs
}
0.1+0.2 ~= 0.3 //true
infix operator ~= : ComparisonPrecedence
func ~=<T> (lhs:T,rhs:T)->Bool where T : FloatingPoint {
return lhs == rhs || lhs.nextDown == rhs || lhs.nextUp == rhs
}
0.1+0.2 ~= 0.3 //true
本文标题:Swift 浮点数比较是否相等
本文链接:https://www.haomeiwen.com/subject/ktxyoftx.html
网友评论