I'v tried following code when learning the mutation function of structure type
struct SelfMutaPoint {
var x = 0.0, y = 0.0
mutating func moveBy(x deltaX: Double, y deltaY: Double) {
self = SelfMutaPoint(x: x + deltaX, y: y + deltaY)
}
}
var someSelfMutaPoint = SelfMutaPoint()
someSelfMutaPoint.moveBy(x: 1.3, y: 3.4) //print "SelfMutaPoint(x: 1.3, y: 3.3999999999999999)\n"
print(someSelfMutaPoint)
print(0.0 + 3.4) // print "3.4\n"
Question:
It is the same operation (0.0 + 3.4) I've applied on, why the operation inside SelfMutaPoint method would leads to a different precision than it placed inside the print function of which from the standard library? (please see the comments in the code above)
Note: It always has "problems" with x.4 digits, I guess it has something to do with how rounding works in computer.
Many Thanks