Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-01-12 16:42:35


"Jan Langer" <jan_at_[hidden]> wrote in message
news:btv0n2$i3o$1_at_sea.gmane.org...
> Andy Little wrote:
> > I have done a bit of er hacking.
[snip]
> > Shut your eyes and think of nice things before you take a look
> > Header enclosed.
>
> i'd like to suggest the following implementation:
>

[implementation]

>
> the double gcd computation can be saved, and the reduce_rat can be
> eliminated by using type inside the class.
>
> but the real point i want to make is that reduction does the following:
> rat <1, -2> => rat <-1, 2>,
> rat <-1, -2> => rat <1, 2>
> the sign of the denominator is always positive after reduction.

Yep :-) :-)

>
> ps: andy, what is the specialization of multiplies and divides good for,
> which use the default arg for the second factor's denominator?

hmm don't know...I'm having problems with divides, probably because I'm into
hack^2.
(Apologies Matt)

Where I would use multiplies | divides it is in power and root:

    q_time::s t(1); // made from rats, possibly rats and int_s -->
    power< rat<1,2> > (t); // e.g t ^0.5
    root<2>(t) ; // e.g t^0.5 same

Other point, I would also like to do:
 plus<int_<1> ,rat<1,2> > etc.
equal_to<int_<1>,rat<3,3> > --> true
ideally though rat<3,3> etc is always reduced to int_<1>,
 but no accounting for users.

Ah well bang goes compile time :-)

regards
Andy Little


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk