Swift Rational - Swift package for working with rational numbers

Generally speaking, the whole point of rational arithmetic is to have exact computations; if you don't need it to be exact, then floating-point is superior in every way to rationals--it's both more efficient from a performance perspective and has smaller worst-case error at any given bitwidth. Saturating is inherently an inexact operation--it's another form of rounding.

5 Likes

I meant to saturate to NaN to indicate an error (similar to how FP is doing that). If you get an error in that form you know something is bad. Similar to FP this could be a signalling error via an appropriate opt-in.