If you guys 'd done your math, you'd know there is an ancient algorithm for approximating numbers by fractions and its called continued fractions.<br><br><div class="gmail_quote">On 16 December 2011 18:38, Lorenzo Sutton <span dir="ltr"><<a href="mailto:lorenzofsutton@gmail.com">lorenzofsutton@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">On 16/12/11 16:05, Alexandre Torres Porres wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
looks like a job for an external<br>
</blockquote></div>
Not really answering the OP question but something could be done in Python:<br>
<br>
def find_frac(num):<br>
f = float(num)<br>
last_error = 1000<br>
best = (0,0)<br>
for i in xrange(1,1001):<br>
for j in xrange(1,i+1):<br>
divide = (float(i) / float (j))<br>
if divide == f:<br>
return ((i,j),0)<br>
err = abs(divide - f)<br>
if err < last_error:<br>
best = (i,j)<br>
last_error = err<br>
return (best,last_error)<br>
<br>
This would try to find the exact fraction or the one with the smallest error (trying up to 1000/1000). It would return (numerator, denominator, error). Guess it would work well at least up to 100 but only for positive numbers... and... not for numbers < 1.. and surely it's not optimised etc. etc. :)<br>
<br>
>>> find_frac(2)<br>
((2, 1), 0)<br>
>>> find_frac(1.5)<br>
((3, 2), 0)<br>
>>> find_frac(1.<u></u>333333333333333333333333333)<br>
((4, 3), 0)<br>
>>> find_frac(2.4)<br>
((12, 5), 0)<br>
>>> find_frac(2.8)<br>
((14, 5), 0)<br>
>>> find_frac(2.987654321)<br>
((242, 81), 1.234568003383174e-11)<br>
>>> find_frac(50.32)<br>
((956, 19), 0.004210526315787888)<br>
>>> find_frac(50.322)<br>
((956, 19), 0.006210526315790332)<br>
>>> find_frac(50.4)<br>
((252, 5), 0)<br>
>>> find_frac(10.33)<br>
((971, 94), 0.00021276595744623705)<br>
>>> find_frac(10.<u></u>33333333333333333333333333)<br>
((31, 3), 0)<br>
<br>
Lorenzo.<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
<br>
2011/12/16 i go bananas <<a href="mailto:hard.off@gmail.com" target="_blank">hard.off@gmail.com</a> <mailto:<a href="mailto:hard.off@gmail.com" target="_blank">hard.off@gmail.com</a>>><div class="im"><br>
<br>
actually, i'm not going to do anything more on this.<br>
<br>
i had a look at the articles claude posted, and they went a bit<br>
far over my head.<br>
<br>
my patch will still work for basic things like 1/4 and 7/8, but i<br>
wouldn't depend on it working for a serious application. As you<br>
first suggested, it's not so simple, and if you read claude's<br>
articles, you will see that it isn't.<br>
<br>
it's not brain science though, so maybe someone with a bit more<br>
number understanding can tackle it.<br>
<br>
<br>
<br>
On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres<br></div><div class="im">
<<a href="mailto:porres@gmail.com" target="_blank">porres@gmail.com</a> <mailto:<a href="mailto:porres@gmail.com" target="_blank">porres@gmail.com</a>>> wrote:<br>
<br>
> i had a go at it<br>
<br>
thanks, I kinda had to go too, but no time... :(<br>
<br>
> yeah, my patch only works for rational numbers.<br>
<br>
you know what, I think I asked this before on this list,<br>
<br>
deja'vu<br>
<br>
> will have a look at the article / method you posted, claude.<br>
<br>
are you going at it too? :)<br>
<br>
by the way, I meant something like 1.75 becomes 7/4 and not<br>
3/4, but that is easy to adapt on your patch<br>
<br>
thanks<br>
<br>
cheers<br>
<br>
<br>
<br>
2011/12/16 i go bananas <<a href="mailto:hard.off@gmail.com" target="_blank">hard.off@gmail.com</a><br></div>
<mailto:<a href="mailto:hard.off@gmail.com" target="_blank">hard.off@gmail.com</a>>><div class="im"><br>
<br>
by the way, here is the method i used:<br>
<br>
first, convert the decimal part to a fraction in the form<br>
of n/100000<br>
next, find the highest common factor of n and 100000<br>
(using the 'division method' like this:<br>
<a href="http://easycalculation.com/what-is-hcf.php" target="_blank">http://easycalculation.com/<u></u>what-is-hcf.php</a> )<br>
<br>
then just divide n and 100000 by that factor.<br>
<br>
actually, that means it's accurate to 6 decimal places, i<br>
guess. well...whatever :D<br>
<br>
<br>
<br>
<br>
<br></div><div class="im">
______________________________<u></u>_________________<br>
<a href="mailto:Pd-list@iem.at" target="_blank">Pd-list@iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/<u></u>listinfo/pd-list</a><br>
</div></blockquote><div><div></div><div class="h5">
<br>
<br>
______________________________<u></u>_________________<br>
<a href="mailto:Pd-list@iem.at" target="_blank">Pd-list@iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/<u></u>listinfo/pd-list</a><br>
</div></div></blockquote></div><br>