Companion program for Joe Horn’s continued fractions article
|
09-13-2023, 10:50 PM
(This post was last modified: 09-16-2023 06:00 PM by Albert Chan.)
Post: #8
|
|||
|
|||
RE: Companion program for Joe Horn’s continued fractions article
Perhaps a simple linear search?
Denominator to seek normally small anyway. Because we never skip, denominator guaranteed smallest! This has the advantage of only needing fast float. (It is hard to get exact CF coefs. with float) Code: function frac_between(a,b) lua> frac_between(3.1415, 3.1416) 333 106 lua> frac_between(1.8, 1.9) 9 5 lua> frac_between(1.8, 1.8) 9 5 lua> frac_between(1.8, 1.7) 7 4 lua> frac_between(1.8, 1.6) 5 3 lua> frac_between(1.8, 1.5) 3 2 lua> frac_between(-pi, -pi*.99) -25 8 Update: ceil(a*d) <= floor(b*d) test simplified to (a*d) <= floor(b*d) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)