swiftobjective-ccgfloat

What is CGFloat.leastNonzeroMagnitude equivalent in Obj-C


What is the equivalent of CGFloat.leastNonzeroMagnitude equivalent in Objective-C? I googled but could not find any answer.


Solution

  • Note that the documentation of leastNonzeroMagnitude says:

    Compares less than or equal to all positive numbers, but greater than zero. If the target supports subnormal values, this is smaller than leastNormalMagnitude; otherwise they are equal.

    So the value of this also depends on "if the target supports subnormal values". Looking at the implementation, we can see:

    public static var leastNonzeroMagnitude: ${Self} {
    #if arch(arm)
      // On 32b arm, the default FPCR has subnormals flushed to zero.
      return leastNormalMagnitude
    #else
      return leastNormalMagnitude * ulpOfOne
    #endif
    }
    

    It turns out that ARM is the target that doesn't "support subnormal values". :)

    If you translate the two branches into Objective-C separately, it would be:

    CGFLOAT_MIN
    

    and

    CGFLOAT_MIN * CGFLOAT_EPSILON