I'm seeing some extremely weird behavior in my macOS project, which I am easily reproducing in the REPL.
Float(double) outputs different results than
double.flatMap(Float.init). I understand there must be a different
init overload invoked when using
flatMap, but why? Looks like a bug in the Swift compiler to me, but I'm not sure, probably there is something I'm missing.
Any help on shedding more light on the matter is much appreciated.
1> let d: Double? = 0.4 d: Double? = 0.40000000000000002 2> d.flatMap(Float.init) $R0: Float? = nil 3> Float(d!) $R1: Float = 0.400000006
Edit: Indeed, another overload was triggered, based on the detailed explanation given by @lukasa
4> d.flatMap(Float.init(_:)) $R2: Float? = 0.400000006