Is there a performance diff using CGFloat with or without postfix .f in Objective-C

cgfloat, ios, objective-c, performance

Solution

1.2 is a `double`; i.e. 64-bit double-precision floating point number.

1.2f is a `float`; i.e. 32-bit single-precision floating point number.

In terms of performance, it doesn't matter as the compiler will convert literals from `float` to `double` and `double` to `float` as necessary. When assigning floating-point numbers from functions, however, you will most likely need to cast to avoid a compiler warning.

Problem

Should I be writing CGFloat values with postfix `f` or not? ``` CGFloat fValue = 1.2; ``` vs. ``` CGFloat fValue = 1.2f; ``` I know that this postfix define a float value. But is it necessary, does it make sense, are there any performance differences between using those two or is this just visual presentation so you can quickly define value type (e.g. float in this case)?

Original source

Related problems