Boost logo

Boost :

From: Andras Erdei (aerdei_at_[hidden])
Date: 2005-03-26 05:06:44


Jonathan Turkanis wrote:

>> template < class unlimited >
>> class unlimited

> Do I understand correctly that rational::unlimited would be like the current
> rational,

it would be intended for unlimited precision (bigint) types, and be
very similar to the current rational (except that it can use expression
templates to avoid executing euclid's algorithm at each operation in
a complex expression, and an implementation geared towards bigints)

>> template < typename limited , policy rounding = round >
>> class fxs_

>> template < biggest_builtin limit = INT_MAX , policy rounding =
>> round > class fxs

> while rational::fxs would provide a separate interface for rationals
> based on built-in integral types?

fxs_ for both built-in and UDT, and fxs for built-ins and pre-known UDTs
(and all UDTs if we find a way)

> Would there be any shared implementation?

not likely between unlimited and limited (fxs), unless it turns out that
expression templates can also have some utility for limited types (and no
runtime impact when not needed)

> Is fxs for power-users too, or just fxs_?

just fxs_

> I agree that a better name than "fxs" is needed. Could you give me a hint what
> it means? ;-)

it is an implementation detail leaked to the interface :O)

fxs stands for "FiXed Slash finite precision rational"

_oversimplified_ explanation:

fxs (and boost::rational when not used with bigints) represent numbers in a
way similar to fixed point

             +----+ +-------------------+ +--------------------+
fixed point |sign| |fixed integer field| |fixed fraction field|
             +----+ +-------------------+ +--------------------+

             +----+ +---------------------+ +-----------------------+
fxs/rational |sign| |fixed numerator field| |fixed denominator field|
             +----+ +---------------------+ +-----------------------+

another option is to use a "floating slash" representation like floating point
numbers

               +----+ +--------------------+ +--------------------+
floating point |sign| |fixed mantissa field| |fixed exponent field|
               +----+ +--------------------+ +--------------------+
                                ^ |
                                | |
                                +----------------------+

               +----+ +-------------------+ +-----------------+
floating slash |sign| |fixed num/den field| |fixed slash field|
               +----+ +-------------------+ +-----------------+
                                ^ |
                                | |
                                +----------------------+

this would allow representing very big numbers (when the slash position is
right to the num/den field the denominator is 1) and very small numbers (when
the slash poition is left to the num/den field the numerator is 1)

br,
andras


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