Solved

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

Posted on 2008-06-22
4
3,265 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
ID: 21841015
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
ID: 21841625
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
ID: 21841696
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
ID: 21845157
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Handle KeyDown for ToolStripDropDownButton, ToolStripMenuItem 3 27
Variable Event ? 3 28
Why  my code (program) build with old compiler? 11 47
No Data for DropDown List 2 26
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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