Skip to content

Instantly share code, notes, and snippets.

@pofat
Created November 8, 2017 15:15
Show Gist options
  • Save pofat/27b847808cd2271634d74e6e25456a5b to your computer and use it in GitHub Desktop.
Save pofat/27b847808cd2271634d74e6e25456a5b to your computer and use it in GitHub Desktop.
extension Float {
var toInt32: Int32 {
// Directly bitwise copy and expressed as Int32
return Int32(bitPattern: self.bitPattern)
}
}
lef f1 = Float(338_556)
let f2 = f1 + f1.ulp
// Differecne between two int32 is actually the distance in ulp
if abs(f1.toInt32 - f2.toInt32) <= 1 {
print("Two float are equal")
} else {
print("Not equal")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment