Topic: Is anything like this already written?


Author: dreamers@netcom.com (Earl and Carmella Brown)
Date: Sat, 28 May 1994 14:54:33 GMT
Raw View

I am interested in finding a template math class something like:

template class<t> TBiggerNumbers<t> {
public:
   TBiggerNumbers<t>(<t>);
   TBiggerNumbers<t>(TBiggerNumbers<t>);

   // for each operator 'x':
   operator x(<t>);
   operator x(TBiggerNumbers<t>);

private:
   t m_LowOrder;
   t m_HighOrder;
};

This class would allow re-creation of the 'int' type by using 'char' for 't',
and the 'long' type by using 'int' for 't'.

It should then be able to be reapplied:

typedef TBiggerNumbers<char>     BNINT;
typedef TBiggerNumbers<BNINT>    BNLONG;
typedef TBiggerNumbers<BNLONG>   BNDLONG;       // 64-bit numbers
typedef TBiggerNumbers<BNDLONG>  BNQUADLONG;    // 128-bit numbers
typedef TBiggerNumbers<BNQLONG>  BNOCTLONG;     // 256-bit numbers
...

I think you get the picture.  I may be way off base, here, but I think that
I could do this:

// start code fragment
typedef TBiggerNumbers<long>     BNDLONG;       // 64-bit numbers
typedef TBiggerNumbers<BNDLONG>  BNQLONG;       // 128-bit numbers

const BNDLONG dlEighteenPoints((BNDLONG)1000000000 * (BNDLONG)1000000000);
BNQLONG qlHugeNumber(5 * dlEighteenPoints);
//...mess around with qlHugeNumber...

BNQLONG qlDecimalValue = qlHugeNumber % dlEighteenPoints;
// end code fragment

and yield faster fixed-point operations of up to 18 decimal places (maybe
more, my mind's been too boggled by all of this) than the current float
data type offers.

If this is true, it could be modified yet again for even more speed, and a
similar class could be built to handle a fixed set of digits as a derived
class:

template class<t> TFixedPoints<t> : public TBiggerNumbers<t>
{
/*
   All operations would chain to parent methods
*/
public:
   t GetNonDecimals()   {return m_HighOrder;};
   t GetDecimals()      {return m_LowOrder;};
}

The only problem I can see is that a modification would need to be made
to avoid the highest decimal-point value from being .65535 in the case
of an int - the highest decimal-point should always be all '9's:9999 in the
case of int-based numbers.
Some method would need to be built which would calculate the largest power
of 10 to fit within the base data type (<t>), and that would be used modulus
to define the actual decimal point value.

Is there anything like this already available?
Thanks,

Earl
--
The house of love                      Dreamers@netcom.com