While I was playing and testing various things with SwiftUI
.
I found this bizarre situation. It is I guess related to the limit value that Double
can handle, but anyway I thought it was weird enough to make a post. And hopefully someone can explain exactly what is happening or let me know where I made a mistake.
It seems like any odd value for t in the following code will cause the same kind of trouble.
let v:Double = 13082761331670030, t:Double = 1
var u:Double
u = v - t;
u += t;
if u == v {print("All is right.")}
else {
print("This is weird. We now have:")
print("v = \(String(format: "%.0f",v)) and u = \(String(format: "%.0f",u))")
}
Executing the code leads to:
u != v