I want to do Double.pi - Float.pi
, but I am getting an error:
Binary operator '-' cannot be applied to operands of type 'Double' and 'Float.
When I typecast Float
to Double
or Double
to Float
(for example: Double(Float.pi))
, the result is wrong. How can I subtract them?
let floatPi = Float.pi
let Pi = Double.pi
print("float pi = \(floatPi)")
print("double pi = \(Pi)")
let substraction = Pi - floatPi
print(substraction)
Here is the result from the above:
float pi = 3.1415925
double pi = 3.141592653589793
error: MyPlayground.playground:20:23: error: binary operator '-' cannot be applied to operands of type 'Double' and 'Float' let substraction = Pi - floatPi
When I try this:
let floatPi = Double(Float.pi)
The result is:
float pi = 3.141592502593994
double pi = 3.141592653589793
1.5099579897537296e-07