objecthub / swift-numberkit

Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FloatingPoint to Rational

thelonious opened this issue · comments

Is there an initializer or method to convert floats and doubles to rationals? I ended up writing my own conversions to Rational, but I wanted to check if I'm overlooking already existing support for that.

Good point! I've added a new constructor to Rational which approximates a given Double up to a given precision.

That's an interesting implementation. Thanks for adding that!