Search code examples
constantsswift3cgfloat

How do I discover the lowest negative possible CGFloat?


I know of these values:

  • CGFloat.infinity, which is greater than
  • CGFloat.greatestFiniteMagnitude, which is greater than
  • CGFloat.leastNormalMagnitude, which is greater than
  • CGFloat.leastNonzeroMagnitude, which is greater than
  • 0

but it stops there... as far as I can tell. Where are the negative values? I imagine maybe it's as easy as placing a - before them, but then I worry that there might be strange exceptions.

How do I find the key negative numbers in CGFloat? Critically, the lowest negative non-infinite number.


Solution

  • Floating point numbers have a sign bit and negating them changes this sign bit to the opposite value (there is actually a negative zero).

    Just put a minus before them. The negation is well defined.