Convert __FLT_EPSILON__ from Objective-C to Swift

I have this line of code in Objective-C and I absolutely need to "translate" it to Swift.

BOOL hasBlur = blurRadius > __FLT_EPSILON__

      

Unfortunately I am getting this error:

Using unresolved identifier __FLT_EPSILON _

Could you help me? Thanks to

+3


source to share


4 answers


__FLT_EPSILON__

- predefined compiler macro, 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

      

+4


source


For fast 3.1 or higher

CGFloat.ulpOfOne

      



OR

double.ulpOfOne

      

+4


source


It looks like it comes from an Objective C line that looked like this:

#define __FLT_EPSILON__ 1.19209290e-7F

      

(Source: this thread ). So you can safely replace it here with your literal value.

0


source


just use this: let FLT_EPSILON = CGFloat (FLT_EPSILON)

0


source







All Articles