Hacker News new | ask | show | jobs
by hyperpape 2751 days ago
Does that work for floats?
1 comments

Yes, if you use the pattern matching operator I suggested to the original comment's author:

  $ swift
  Welcome to Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1). Type :help for assistance.
    1> let x = 3
  x: Int = 3
    2> let y = 3.0
  y: Double = 3
    3> 2...4 ~= x
  $R0: Bool = true
    4> 2...4 ~= y
  $R1: Bool = true
Floats that aren’t equivalent to ints: 2.5.

In some languages, similar constructs test membership in a list/range, rather than an inequality.