[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] Conversion decimal into fractional
There's not much need for a Rational number class, I think, and working
with strings is not nice, it should be left only for last moment
displaying and not for calculating. Using either the method I wrote or the
one jmc just posted you can add to what you were doing:
> x=Array.fill(10, {arg i, n=2; (n+i).asString ++"/"++ (n+i-1)}).postln;
> y = x.collect(_.interpret);
z = y.collect(_.asFraction)
[ [ 2, 1 ], [ 3, 2 ], [ 4, 3 ], [ 5, 4 ], [ 6, 5 ], [ 7, 6 ], [ 8, 7 ], [
9, 8 ], [ 10, 9 ], [ 11, 10 ] ]
Doing the math on this array pairs is not such a big hassle and is
equivalent to rational arithmetic. Actually your'e just a few steps close
to having a sort of Rational class if you make the appropiate methods for
the math operations. I use it to change from frequencies to ratios and
durations a lot and haven't found it too cumbersome to deal with. The rest
of the discussion is about the actual problems of dealing with different
kinds of numbers when computers only understand binary.
(my 2 peso cents which is about 1/6 of a dollar cent, which is really
close to nothing)
js