Boost logo

Boost :

Subject: Re: [boost] [review] Multiprecision review (June 8th - 17th, 2012)
From: John Maddock (boost.regex_at_[hidden])
Date: 2012-06-29 08:23:10


> 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 )

There is a mention of this in the introduction about 2/3 of the way down
http://svn.boost.org/svn/boost/sandbox/big_number/libs/multiprecision/doc/html/boost_multiprecision/intro.html

The problem is this:

The result of a+b is an expression template, the result of a*b is different
expression template type, so:

1) Template argument deduction for std::max fails.
2) Even if template argument deduction had succeeded, you would be passing
the "wrong type" to the function - an expression template and not a number,
so for example given:

foo(a+b)

template arg deduction would succeed for foo (assuming foo is a template
function), but you'd likely get inscrutable errors inside the body of foo as
a result of passing something that's not actually a number to it.

So you either have to:

* Explicitly cast the arguments to the underlying number type when calling a
template function. Or,
* Call an explicit template instance by passing the function the template
args inside <>.

Note that none of the above applies when calling non-template functions as
all the usual conversions apply, I've also fixed up the multiprecision and
Math lib's so they interoperate without having to worry about any of this.
I'd forgotten all about std::min/max, but I'd add overloads for those too
(and any other std lib functions I spot).

Cheers, John.


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