Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::complex and std::pow

28 views
Skip to first unread message

Christopher Pisz

unread,
May 21, 2015, 6:19:38 PM5/21/15
to
Trying to update my project to use a newer compiler. It started
complaining about my use of std::pow being ambiguous and having multiple
overloads to choose from.

From what I can tell std::pow now uses something called std::complex. I
looked that up and it represents complex numbers. Fair enough. I don't
need to deal with a complex number, but I don't know if I have to use it
to get the solution to x^y.

Is this how I am supposed to use it?

const std::string fractionalPart = "123456789"

const double inputTicksPerSecond =
std::pow<double>(std::complex<double>(10.0),
std::complex<double>(fractionalPart.size())).real();

I'm a bit confused.


--
I have chosen to troll filter/ignore all subthreads containing the
words: "Rick C. Hodgins", "Flibble", and "Islam"
So, I won't be able to see or respond to any such messages
---

Barry Schwarz

unread,
May 21, 2015, 7:01:29 PM5/21/15
to
The fact that there is a complex version of pow only comes into play
if you actually call the function with at least one complex argument.
Otherwise you end up with the "real" version of the function.

Is your compiler C++98 or C++11? The two versions have different
prototypes.

Why don't you show us the actual types of x and y and the error
message that is generated when you compile the expression pow(x,y).

On Thu, 21 May 2015 17:19:29 -0500, Christopher Pisz
<nos...@notanaddress.com> wrote:

>Trying to update my project to use a newer compiler. It started
>complaining about my use of std::pow being ambiguous and having multiple
>overloads to choose from.
>
> From what I can tell std::pow now uses something called std::complex. I
>looked that up and it represents complex numbers. Fair enough. I don't
>need to deal with a complex number, but I don't know if I have to use it
>to get the solution to x^y.
>
>Is this how I am supposed to use it?
>
>const std::string fractionalPart = "123456789"
>
>const double inputTicksPerSecond =
>std::pow<double>(std::complex<double>(10.0),
>std::complex<double>(fractionalPart.size())).real();
>
>I'm a bit confused.

--
Remove del for email

Christopher Pisz

unread,
May 21, 2015, 7:14:51 PM5/21/15
to
Top posting is frowned upon.

I did show the types:
x = 10.0
y = fractionalPart.size() with fractionalPart being an std::string

Both the old and new compilers are C++98 afaik.
I went from Visual Studio 2012 using the 2010 platform toolset to 2013
using the 2010 platform toolset.

The error is that it is an ambiguous call between global pow, <cmath>
pow and <complex> pow. The actual error message is too long for me to be
happy with copy pasting it.

I think I can solve this problem just by using ::pow instead of std::pow.

Öö Tiib

unread,
May 22, 2015, 1:29:16 AM5/22/15
to
C++11 standard reworded the 'pow' requirements and who knows what
Microsoft made out of it.
Perhaps it is confused because the size of string is unsigned type.
On that case casting it to double might be enough.

Paavo Helde

unread,
May 22, 2015, 1:41:01 AM5/22/15
to
Christopher Pisz <nos...@notanaddress.com> wrote in news:mjlljc$615$1@dont-
email.me:

> Trying to update my project to use a newer compiler. It started
> complaining about my use of std::pow being ambiguous and having multiple
> overloads to choose from.
>
> From what I can tell std::pow now uses something called std::complex. I
> looked that up and it represents complex numbers. Fair enough. I don't
> need to deal with a complex number, but I don't know if I have to use it
> to get the solution to x^y.

You don't need to use complex numbers if you are not working with them. For
a start, try to ensure that both arguments passed to std::pow() are of the
same type.

[gibberish snapped]

hth
Paavo

Paavo Helde

unread,
May 22, 2015, 1:48:19 AM5/22/15
to
Christopher Pisz <nos...@notanaddress.com> wrote in
news:mjloqr$guh$1...@dont-email.me:

>
> The actual error message is too long for me to be
> happy with copy pasting it.

Why? Do you believe it would fasten the universe heat death or something?

Cheers
Paavo



Juha Nieminen

unread,
May 22, 2015, 5:51:11 AM5/22/15
to
Christopher Pisz <nos...@notanaddress.com> wrote:
> Trying to update my project to use a newer compiler. It started
> complaining about my use of std::pow being ambiguous and having multiple
> overloads to choose from.

If both parameters are of type double, there should be no problem.

Are both parameters of that type in your code?

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
0 new messages