[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Conversion decimal into fractional



Hey Ph.E,

Just to clarify -- your request can go in one of two
directions:

- a class RationalNumber that stores the numerator and
denominator and does math in terms of these
- or, a display method to display a floating-point
number as a rational fraction

The second is a lot easier. slach's e-mail (quoted
below) gives you one technique. I gave you another one
on the sc forum. What else is needed?

One of the design philosophies of sc is to keep the
base library pretty clean, without a lot of "this and
that" that people think would be "nice to have." I've
made numerous suggestions like this and been shot
down, often. It's not fun, but I've come to agree that
the base class library would be even more confusing
than it is now if the test for inclusion were not so
strict.

One of the reasons I created my library is as a place
where I can add enhancements without asking for
permission.

So, I'd say, you have a couple of options... pick one
and make the most of it!
hjh

--- Juan Sebastian Lach Lau <slach@xxxxxxxxx> wrote:

> Hi Philippe,
> 
> I did some additional methods for SimpleNumber and
> Integer that were
> posted a few months ago. There's asFraction and a
> factorize method. The
> algorithm is done by Farey fractions which gives
> very good aproximations.
> Ex:
> 
> pi.asFraction
> [ 22, 7 ]
> 
> pi.asFraction(1000)
> [ 355, 113 ]
> 
> 1000.factorize
> 
> List[ 2, 2, 2, 5, 5, 5 ]
> 
> 1000.factorsList
> 
> List[ [ 2, 3 ], [ 5, 3 ] ]
> 
> I don't have much time now to explain the other
> methods (they're in the
> list archives) but can do so later on or tomorrow if
> there is interest.


=====
____   James Harkins /// dewdrop world
\  /   jamshark70@xxxxxxxxx
 \/    http://www.dewdrop-world.net

"... love and hot pants, peace, harmony..."
  -- Dick Lee, Hot Pants: The Musical