Search code examples
swiftinfinity

INFINITY in Swift Lang


According to Apple's documentation, Swift doesn't support preprocessor directives. In C/Objective-c the "INFINITY" definition is very useful for some checks. So, How do I get a number that never is less that another?


Solution

  • There is already buildin infinity and also a check function. And you could also directly compare them with <.

    var infinity = Double.infinity
    var isInfinite = infinity.isInfinite
    var someDouble = 234432.0
    if someDouble < infinity {
        println("Less than")
    } else {
        println("Small than")
    }
    // And the answer is Less than.