INFINITY in Swift Lang

Daniel picture Daniel · Jun 4, 2014 · Viewed 15.4k times · Source

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?

Answer

sunkehappy picture sunkehappy · Jun 4, 2014

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.