Stop to! rounding?

Jay Norwood jayn at prismnet.com
Wed Jul 3 06:21:26 PDT 2013


On Wednesday, 3 July 2013 at 08:23:40 UTC, monarch_dodra wrote:
> On Wednesday, 3 July 2013 at 06:18:28 UTC, Jonathan M Davis 
> wrote:
>> On Wednesday, July 03, 2013 08:11:50 Josh wrote:

> Long story short, I think both would be a great addition to 
> phobos/D. I'd personally really want to play with decimal 
> floats: They are slower, less precise and have less range, but 
> are more "exact" in base 10 than traditional floats. And when 
> printed in Base 10, are *always* exact.

This arbitrary precision c++ arithmetic package has a flexible 
feature of allowing selection of the internal base.  The default 
base 10.  Much of it is implemented in c++ templates. I put a 
small excerpt below.

http://www.hvks.com/Numerical/arbitrary_precision.html

/// Description:
///   Add operator for float_precision + <any other type>
///   no const on the lhs parameter to prevent ambigous overload
///
template <class _Ty> inline float_precision operator+( 
float_precision& lhs, const _Ty& rhs )
    {
    float_precision c(rhs);

    if( lhs.precision() > c.precision() )
       c.precision( lhs.precision() );

    return c += lhs;
    }


More information about the Digitalmars-d-learn mailing list