Setting a maximum demoninator for fractions
|
10-04-2023, 01:03 AM
(This post was last modified: 10-04-2023 01:05 AM by Albert Chan.)
Post: #8
|
|||
|
|||
RE: Setting a maximum demoninator for fractions
(10-03-2023 02:44 PM)Albert Chan Wrote: if abs((n1-d1*x)*q) <= abs((p-q*x)*d1) THEN p:=n1; q:=d1; END; This test has trouble if numerator is huge, with possibly catastrophic cancellation issue. We like numerator small, so my next version remove rounded integer part of x, before the test. I also squared both sides to remove abs, with equivalent test as product of 2 dot products. HP Prime HOME dot product work with higher precisions, thus more accurate. Cas> factor(((p-q*x)*d1)^2 - ((n1-d1*x)*q)^2) → (q*n1-p*d1)*(2*x*q*d1-q*n1-p*d1) Code: EXPORT CF(x, dmax) // closest fraction |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)