Solved

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

Posted on 2008-06-22
4
3,299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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:…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

734 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