dagronf/DSFRational
A Swift extension for floating point values to return rational components
Notes
The algorithm arises from a comment on GameDev.net by user John Bolton.
Here is an algorithm for converting a value to the closest fraction (given a maximum value for the denominator). It is based on Farey Sequences. It is probably much faster than finding GCDs and the results are much more useful. For example, using the suggestions above, .333333 will be converted to 333333/1000000, which is probably not what you want. Using this algorithm, you will get 1/3.
Package Metadata
Repository: dagronf/DSFRational
Stars: 1
Forks: 0
Open issues: 0
Default branch: master
Primary language: swift
License: MIT
Topics: objective-c, rational, swift
README: README.md