Created
November 8, 2017 15:15
-
-
Save pofat/27b847808cd2271634d74e6e25456a5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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