Why does Swift not support rational numbers?

I believe OP actually meant "fixed" point math hence the usage of 32/64 bit UInt for both numerator and denominator in the leading example:

typealias NaturalNumber = Uint
let numerator  : NaturalNumber
let denominator: NaturalNumber

I would welcome first class support for Fixed numbers. Don't do finance, but hate when I see floating point gotchas in graphics, e.g. rect math acting weirdly because of this:

let a = 100.33333333333333333333333
let b = a + 100
let c = b - 100
assert(a == c) // Assertion failed
1 Like