Solved

<math.h> error in Microsoft Visual C++

Posted on 2008-06-22
4
3,240 Views
Last Modified: 2013-11-26
I've created a header file which contains lines like this :

Value = 1*pow(10,13) + 3 * pow(10.0,4) , where Value is an unsigned long long.

The header file was working perfectly on Borland C++ Builder 6. I've tried to run it using Microsoft Visual Studio 2008,(Visual C++) and i get errors like this:

c:\my documents\visual studio 2008\projects\chrysaor\chrysaor\File2.h(168) : error C2668: 'pow' : ambiguous call to overloaded function
        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\math.h(575): could be 'long double pow(long double,int)'
        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\math.h(527): or       'float pow(float,int)'
        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\math.h(489): or       'double pow(double,int)'
        while trying to match the argument list '(int, int)'

Why this happens and how do I fix it?

Thanks a lot.
0
Comment
Question by:Chrysaor
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
sistemu earned 150 total points
Comment Utility
Hi
Try using:
Value = 1*pow(10.0,13) + 3 * pow(10.0,4)

OR:
Value = 1*pow((double)10,13) + 3 * pow((double)10.0,4)

Function pow has 3 overloads:
~ long double pow(long double,int)
~ float pow(float,int)
~ double pow(double,int)
but either one corresponds to the way you call them.
0
 
LVL 11

Expert Comment

by:cup
Comment Utility
Since your result is a long long, just to be safe, make the 1 and 3 1LL and 3LL respectively.
0
 
LVL 11

Expert Comment

by:cup
Comment Utility
Since your result is a long long, just to be safe, make the 1 and 3 1LL and 3LL respectively.
0
 
LVL 7

Assisted Solution

by:johnnash1180
johnnash1180 earned 150 total points
Comment Utility
Hmmmm..
The following may help.

long double Value = 1LL*pow(10.0f,13) + 3LL * pow(10.0f,4);

The complete documentation of pow function at the following URL:
http://msdn.microsoft.com/en-us/library/dt5dakze(VS.71).aspx

Nash J
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now