The result is correct !
What you see is due to internal representation of Double or Float, which is not a decimal representation, but mantissa (significand) and exponent.
So, it is very hard to predict how it is converted in decimal representation (used for print)
Look here:
https://developer.apple.com/documentation/swift/double/1847553-significand
As an example, consider the results from the following:
let a : Double = 16.8
let b : Double = 18.5
let c = b - a
let d = b + a
let e = a * b
print("a = \(a.significand) * 2**\(a.exponent) = ", a)
print("b = \(b.significand) * 2**\(b.exponent) = ", b)
print("c = \(c.significand) * 2**\(c.exponent) = ", c)
print("d = \(d.significand) * 2**\(d.exponent) = ", d)
print("e = \(e.significand) * 2**\(e.exponent) = ", e)
a = 1.05 * 2**4 = 16.8
b = 1.15625 * 2**4 = 18.5
c = 1.6999999999999993 * 2**0 = 1.6999999999999993
d = 1.103125 * 2**5 = 35.3
e = 1.2140625 * 2**8 = 310.8
The key point is that the significand is kept in the range 1.0 ..< 2.0
So, when you compute b-a, you do not get
(1.15625 - 1.05) * 2**4 which would be 0.10625 * 16 = 1.7
but it is transformed to keep significand between 1 and 2, which causes the approximation.
because 0.10625 is not in the range 1.0 to 2.0, hence we need to convert to a new exponent
But it is pretty hard to predict the result:
if we define
let g = a + c
we get :
g = 1.15625 * 2**4 = 18.5
exactly a !!!! No more rounding error.
c has been converted for the computation from 1.6999999999999993 * 2**0 to 0.10625 * 2**4 = 1.7
If this causes a problem, you should use a decimal representation (but probably not as efficient for heavy computation and anyway, they may use transit conversion to Double ! see h ttps://forums.swift.org/t/weird-behaviour-in-decimal/13893/2).
Hope that's clear.