I've got this line of code in Objective-C and I absolutely need to "translate it" to Swift.
BOOL hasBlur = blurRadius > __FLT_EPSILON__
Unfortunately I get this error:
Use of unresolved identifier __FLT_EPSILON_
Can you help me? Thanks
I've got this line of code in Objective-C and I absolutely need to "translate it" to Swift.
BOOL hasBlur = blurRadius > __FLT_EPSILON__
Unfortunately I get this error:
Use of unresolved identifier __FLT_EPSILON_
Can you help me? Thanks
For swift 3.1 OR above
CGFloat.ulpOfOne
OR
Double.ulpOfOne
__FLT_EPSILON__
is a predefined macro of the compiler, apparently not available
in Swift. But <float.h>
defines
#define FLT_EPSILON __FLT_EPSILON__
and this is available in Swift as well:
let hasBlur = blurRadius > FLT_EPSILON
Update: Starting with Swift 4, FLT_EPSILON
is deprecated. See Hiren Panchal's answer for an up-to-date solution.
Looks like it comes from a line of Objective C that looked like:
#define __FLT_EPSILON__ 1.19209290e-7F
(Source: this thread). So you can safely replace it here with its literal value.