[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] Conversion decimal into fractional
On Dec 22, 2004, at 11:19 AM, Juan Sebastian Lach Lau wrote:
This discussion has been very fruitfull for me. Analyzing the factors and
the revised asFraction taught me a lot. Thanks, James.
I made another change for small numbers:
<x-tad-smaller> if (</x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller> < 1.0) {
upper = [1, </x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller>.reciprocal.floor];
lower = [1, upper[1]+1];
}{
lower = [</x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller>.floor, 1];
upper = [lower[0]+1, 1];
};
</x-tad-smaller>
otherwise for (1/53).asFraction you get a succession like
1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 ... 1/50 1/51 1/52 1/53
this change skips all that.
It has the additional effect that if you enter a number less than 1/maxDenominator then you will end up with a better approximation than you asked for, but I don't consider that a bug.
--
james mccartney
http://www.audiosynth.com