Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-03-28 06:29:37


"Jonathan Turkanis" <technews_at_[hidden]> wrote in message
news:d22j79$ag5$1_at_sea.gmane.org...
> David Abrahams wrote:
>> "Jonathan Turkanis" <technews_at_[hidden]> writes:
>>
>>> Dear All,
>>>
>>> Several months ago I became the official maintainer of
>>> Boost.Rational, and am just now getting around to considering
>>> proposed modifications to the library.
>>>
>>> I would like to know:
>>>
>>> 1. Do people use Boost.Rational, and if so, what is it used for, and
>>> with what template parameters?
>>
>> I'm not using it now, but I will probably want to throw it at my
>> upcoming linear algebra code, using an unlimited precision integer
>> type (if I can find one) as the template parameter.
>
> Would it be kosher for me to grab a bigint class from the Yahoo files
> section --
> say the one by Ronald Garcia and Andrew Lumsdaine -- make sure it is in good
> shape, and let it be the default template parameter to rational?

Surely int should be the default parameter (if any). Using bigint turns it from
a relatively lightweight to a heavyweight type. In many uses of rational
the values are unlikely to overflow. Some uses are in dividing a circle into
degrees, minutes, or seconds, power of dimension in a runtime physical-quantity,
Storing imperial lengths eg 1 1/8 " (inch). I would guess that these are the
major uses of rational and all have values in quite a small range.

And of course making bigint the default parameter introduces a dependency, which
is at least untidy.

As far as errors due to overflow, the problem is not actually in the domain of
rational but of the value_type as has been stated before. rational shouldnt
need to know anything about the behaviour of its value_types operations.

BTW why doesnt boost::rational have a 'value_type' member rather than the
obscure 'int_type'?

Further If the mpl rational (or fraction) becomes part of boost:
http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?MPL_TODO_List.
 it would be useful to allow interaction between the compile time and run time
types:

typedef boost::mpl::rational_c<int,1,360> ct;
for (boost::rational<int> rt ; rt <= 1; rt += ct()){...}

Other useful operation might be an integer_cast which throws if denominator != 1

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