I typed this code in Swift playground (Xcode 7.3.1) to see how functions treat their parameters as constants. We are required to add var in front of a parameter's name if we want to change its value. However, I was surprised to see the result of a simple subtraction. Can someone explain why I am getting 0.5999999999999996 instead of 0.6? Here is the code:
func subtract(var x: Double, from y: Double) -> Double {
x = x + 1.0
return y - x
}
let result = subtract(3.2, from: 4.8) // result: 0.5999999999999996