Question: I have an enum for tagged values (this is from a toy Scheme interpreter project), like this:

```
enum Value {
  case int(Int)
  case float(Float)
  case bool(Bool)
  ...
}

```

I wrote an initializer for it:

```
init?(value:Any) {
  switch v {
    case let v as Int: self = .int(v)
    case let v as Float: self = .float(v)
    case let v as Bool: self = .bool(v)
    ...
    default: return nil
  }
}

```

With that, calling `Value(3)` returns an (optional) Value.int(3), as expected. Bool's and the other types work too.

But `Value(0.1)` hits the default case and returns `nil`.

(Edited for correctness and recommended style. Thank you everyone for pointing those issues out.)

Answer: 
The default inferred type for floating point constants is `Double`, not `Float`. It's defined by the swift standard library here: <https://developer.apple.com/reference/swift/floatliteraltype> using the compiler-known `FloatLiteralType` typealias.
The documentation of [type inference](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID322) says:

> 
> Swift always chooses `Double` (rather than `Float`) when inferring the
>  type of floating-point numbers.
> 
> 
> 

If you want to use `Float`, you must explicitly cast the literal:

```
enum Value {
    case Int(Int)
    case Float(Float)
    case Bool(Bool)
    case Double(Double)
    init?(v:Any) {
        switch v {
        case let v as Int: self = .Int(v)
        case let v as Float: self = .Float(v)
        case let v as Bool: self = .Bool(v)
        case let v as Double: self = .Double(v)
        default: return nil
        }
    }
}

Value(v: 0.1) //Infer Double > Result: Double(0.10000000000000001)
Value(v: Float(0.0002)) //Specify Float > Result: Float(0.000199999995)

```