Trying to do some Advent of Code in the christmas holidays, I found a large number and thought I would measure it to see if it was too big to solve using my current naive solution. But what Swift (5.5.2, Xcode 13.2.1) reported was not what I expected:
Welcome to Swift version 5.5.2-dev. Type :help for assistance. 1> 2758514936282235 > Int32.max $R0: Bool = false 2> 2758514936282235 < Int32.max error: repl.swift:2:1: error: integer literal '2758514936282235' overflows when stored into 'Int32' 2758514936282235 < Int32.max ^
I don't know if the error on
2758514936282235 < Int32.max makes sense or not, but the fact that the same error does not occur for
2758514936282235 > Int32.max seems unexpected, and what's even more concerning is that according to Swift, 2 758 514 936 282 235 is less than 2 147 483 647 (
Could this comparison behaviour be related to the one I posted about regarding
Decimal last summer? Why is Decimal.ulp greater than any decimal value itself?