Boost logo

Boost :

Subject: Re: [boost] *** GMX Spamverdacht *** Re: [review] Multiprecision review (June 8th - 17th, 2012)
From: Mario Mulansky (mario.mulansky_at_[hidden])
Date: 2012-06-29 04:48:48


On Thu, 2012-06-28 at 19:38 +0200, Marc Glisse wrote:
> On Thu, 28 Jun 2012, Mario Mulansky wrote:
>
> > My test case is to use floating point multiprecision types as the basis for
> > our odeint library (www.odeint.com). As odeint is fully templatized I could
> > just plug in, say, the cpp_dec_float_50 and the basic routines worked out of
> > the box. The only problem I had was that there seems to be no support for min
> > / max functions for expressions of multiprecision types. So can not write
> >
> > x = max( a+b , a*b )
>
> x = max<cpp_dec_float_50>( a+b , a*b )
> maybe?
>
> (assuming they don't overload max for this library)

I think this would work, but I don't want to do that because then any
user defined non-templatized function would not be found (see example
below). I think the better way is an explicit cast of the arguments:

max( static_cast< mp_type >( a+b ) , static_cast< mp_type >( a*b ) );

as also written in the MP introduction as I just found out.

Example, where the user defined function is not used because it isn't
templatized:

#include <iostream>

struct my_type
{ };

bool operator <( const my_type x , const my_type y )
{ return true; } // for std::max to compile...

bool max( const my_type x , const my_type y )
{
    std::cout << "test" << std::endl;
};

int main()
{
    my_type a , b;

    using std::max;

    max( a , b ); // calls user defined max
    
    max<my_type>( a , b ); // calls std::max, not good

    // user defined max, I think that's the right way:
    max( static_cast<my_type>(a) , static_cast<my_type>(b) );

}


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