Boost logo

Boost :

From: Bill Seymour (bsey_at_[hidden])
Date: 2001-05-14 06:46:20


Daryle Walker asked:
>
> Could/should we have a version of the "div" function
> defined for rational numbers?
>

How about something analagous to fmod(double, double)
and modf(double, double*)?

A while back before I knew about Boost, I wrote a non-templated
rational number class that had member functions:

    int trunc() const
    {
      #if defined(_MSC_VER)
        return div(num, den).quot;
      #else
        return std::div(num, den).quot;
      #endif
    }

    rational modr(rational* iptr) const
    {
        return rational(*this) -= (*iptr = trunc());
    }

    rational rmod(const rational& rhs) const
    {
        rational temp(*this);
        temp /= rhs;
        int i_part = temp.trunc();
        temp -= ipart;
        return temp;
    }

(OK, they should be free functions, not member functions;
but you get the idea.)

Is that what you want?

--Bill Seymour


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