Reputation: 1
var a = 127.0
var b = 5.0
a / b
var c:Float
c = 127
var d:Float
d = 5
c/d
In Playground, a/b returns 25.4, but c/d returns 25.39999961…
Why?
Is this result going to be the same when the code is compiled and run?
Is there something I'm failing to do to get correct arithmetic answers in Swift?
Thanks,
MB
Upvotes: 0
Views: 88
Reputation: 4996
This is because a
and b
are both doubles
, so they have twice the floating point precision compared to floats
.
Upvotes: 1