Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: real to rational number Date: Wed, 19 Apr 2017 13:03:25 -0700 Organization: A noiseless patient Spider Lines: 20 Message-ID: <87mvbcdv1u.fsf@nightsong.com> References: <8c2f9ac1-9fb9-4dc4-a43e-66f50ea2b838@googlegroups.com> <4203a8d4-bd7f-45c4-8552-e6c916e85ee4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="47e0bd6af43efb397f12aac8c938d83c"; logging-data="8376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18su1LdZ9dTj4MXGjehNIfO" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:cTiM02a/nixUgDDpxMKSMm8mvKU= sha1:9K6hxBAYW5QPguIWdtLqeUET0vI= Xref: csiph.com comp.lang.forth:57606 rickman writes: > I don't understand all of the language you are using, but there are an > infinite number of integers and the solution can be found arbitrarily > close to any real value by finding larger value integers. To my > understanding there is *no* single solution unless you restrict the > magnitude of the integers you use. There's two questions being conflated: 1) given a floating point number x, find the smallest pair of integers a,b such that a/b == x to the same precision that x is given in. 2) given an irrational number x, find rational approximations that are as close as possible to x given their size. E.g. for pi, the approximants are 3/1, 22/7, 333/106, 355/113, 103993/33102, 104348/33215, 208341/66317, 312689/99532, 833719/265381, 1146408/364913, etc. Both of these are done with the continued fraction algorithm that I posted. It helps if you have bignum arithmetic for this sort of thing.