octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ambiguous call to "pow(int, unsigned int&)" in __magick_read__.cc:76


From: Júlio Hoffimann
Subject: Re: ambiguous call to "pow(int, unsigned int&)" in __magick_read__.cc:763
Date: Sat, 27 Aug 2011 14:00:36 -0300

Hi all,

I had the same ambiguous promotion problem in the past when migrating from 32bits to 64bits platform with a project mine. An elegant solution is to create a wrapper and use it when appropriate:
// ===  FUNCTION  ======================================================================
//         Name:  pow_int
//  Description:  pow version for two integer arguments
// =====================================================================================
template <typename T>
inline T pow_int ( T base, int exponent )
{
    BOOST_STATIC_ASSERT( std::numeric_limits<T>::is_integer );
    return static_cast<T>( std::pow( static_cast<Real>( base ), exponent ) );
}        // -----  end of template function pow_int  -----

C++ doesn't provide an integer version due to faster overflow, i guess.

Regards,
Júlio.

2011/8/27 Jordi Gutiérrez Hermoso <address@hidden>
On 27 August 2011 04:38, Carlo de Falco <address@hidden> wrote:
> Building the current tip on OSX 10.6 fails in DLD-FUNCTIONS/__magick_read__.cc
> with the following error:
>
> DLD-FUNCTIONS/__magick_read__.cc: In function 'void encode_uint_image(std::vector<Magick::Image, std::allocator<Magick::Image> >&, const octave_value&, bool)':
> DLD-FUNCTIONS/__magick_read__.cc:763: error: call of overloaded 'pow(int, unsigned int&)' is ambiguous
> /usr/include/architecture/i386/math.h:343: note: candidates are: double pow(double, double)
> /usr/include/c++/4.2.1/cmath:373: note:                 long double std::pow(long double, int)
> /usr/include/c++/4.2.1/cmath:369: note:                 float std::pow(float, int)
> /usr/include/c++/4.2.1/cmath:365: note:                 double std::pow(double, int)
> /usr/include/c++/4.2.1/cmath:361: note:                 long double std::pow(long double, long double)
> /usr/include/c++/4.2.1/cmath:357: note:                 float std::pow(float, float)
>
> I can fix the error by changing line 763 to
>
> im.quantizeColors (static_cast<int> (pow (2, static_cast<double> (bitdepth))));
>
> but it doesn't look very clean to me, what is this the correct fix?

If that's the version of pow you intended to call, there is nothing
wrong in disambiguating the call with a cast, especially if it's not a
C-style cast. If that fixes your build, I suggest you push that patch.
I am not seeing this problem on a more recent g++.

- Jordi G. H.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]