On 16/12/11 06:51, i go bananas wrote:
by the way, here is the method i used:

first, convert the decimal part to a fraction in the form of n/100000
next, find the highest common factor of n and 100000
(using the 'division method' like this:
http://easycalculation.com/what-is-hcf.php )

then just divide n and 100000 by that factor.

I don't think that method will give happy results for most simple fractions. Plus it's useful to get approximations that are simpler or more accurate, like 3 or 22/7 or 355/113 for pi..

Your patch doesn't work very well for me:

input: 1/7
fraction: 2857/20000
input: 8/9
fraction: 11111/12500
input: 7/11
fraction: 15909/25000
input: 11/17
fraction: 4313.67/6666.67

(input is "$1 $2"--[/], so as accurate as floating point is...)

actually, that means it's accurate to 6 decimal places, i guess.

There's a way to get a "simple" fraction like 1/7 instead of 143/1000 or whatever, could be possible to implement in Pd? (I've not tried.)

[0] http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-Ratio.html#approxRational

[1] http://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations

well...whatever :D


Claude

_______________________________________________
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to