473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How come I can't use 'sqrt' and 'fabs'?

Vol
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

Vol.

Nov 15 '05 #1
7 9714
Vol wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.


That you are not using a C compiler but probably a C++ compiler
to compile your code. So, your best bet is asking this question
in comp.lang.c++ as it is definitely off-topic and irrelevant
here.

<OT>You are probably passing an integer argument to functions which
are overloaded to have arguments of either type double, or type float
or type long double. This is a Bad Thing, as the compiler tries
to determine the best overloaded function -- and may use different
overloads at different places. This can result in irreproducible
behavior if the source code changes but slightly.
If you use literals, pass one of the right type, e.g.
2.0
2.0F
2.0L
instead of
2
For variables, use an appropriate static_cast<>() (not a C cast!!):
static_cast<double>(my_integer_argument)
</OT>
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #2
Vol wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.


Before posting to any newsgroup check the FAQ.
Nov 15 '05 #3
Michael Mair wrote:
Vol wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

That you are not using a C compiler but probably a C++ compiler
to compile your code. So, your best bet is asking this question
in comp.lang.c++ as it is definitely off-topic and irrelevant
here.

<OT>You are probably passing an integer argument to functions which
are overloaded to have arguments of either type double, or type float
or type long double. This is a Bad Thing, as the compiler tries
to determine the best overloaded function -- and may use different
overloads at different places. This can result in irreproducible
behavior if the source code changes but slightly.
If you use literals, pass one of the right type, e.g.
2.0
2.0F
2.0L
instead of
2
For variables, use an appropriate static_cast<>() (not a C cast!!):
static_cast<double>(my_integer_argument)
</OT>


This is the C++ solution.

If you wanted C: Use a C compiler!


Cheers
Michael

--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #4
Vol wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.


It probably means you are not compiling C code (or as C) since C does
not have overloaded functions.

If this is meant to be C post a *complete* small program exhibiting the
problem, if it is C++ then go to a group dealing in C++ such as
comp.lang.c++

Alternatively delete lines 4, 30, 43 to 1000 inclusive and 1002, destroy
all other copies of your program, and try again.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #5
Martin Ambuhl <ma*****@earthlink.net> writes:
Vol wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"
I already add the math library, what does this error mean? Thanks.


Before posting to any newsgroup check the FAQ.


That's always good advice, but I don't see how the C FAQ answers this
particular question.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #6
On 22 Oct 2005 00:03:53 -0700, in comp.lang.c , "Vol"
<vo********@gmail.com> wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.


You're invoking the C++ compiler perhaps?

This is strictly speaking a compiler-specific problem, you may have
more luck in a compiler specific newsgroup.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #7
Mark McIntyre wrote:
On 22 Oct 2005 00:03:53 -0700, in comp.lang.c , "Vol"
<vo********@gmail.com> wrote:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.


You're invoking the C++ compiler perhaps?


The post you are replying to was from four days ago and the OP received
the same answer from two other people at the time.

Brian
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon | last post by:
Hi, I have a function that always crashes and I am not too sure why. Here is the code, (and the value that cause the crash). #include <math.h> .... bool ConvertToString( double num, char...
11
by: Martin | last post by:
In Plauger's THE STANDARD C LIBRARY (1992) there is the source code for fabs.c (p140). /* fabs function */ #include "xmath.h" double (fabs)(double x) { switch (_Dtest(&x)) { /* test for...
3
by: LeTubs | last post by:
Hi I'm having a bit of problem trying to compile a program..... which uses math.h #include <stdio.h> #include <stdlib.h> #include <math.h> double sxy, sxx, syyy;
13
by: Michael McNeil Forbes | last post by:
I would like to write a module that provides some mathematical functions on top of those defined in math, cmath etc. but I would like to make it work with "any" type that overloads the math...
12
by: Thomas Zhu | last post by:
hello all, n is an 32bit-integer, how to calculate sqrt(n) I know high(n) is the the value, but how to use bit operation to implement this function. thanks in advance. yours Yin
13
by: siggi | last post by:
Hi all, this is a newbie question on : Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32 PC with WinXP In http://www.python.org/doc/2.3.5/lib/module-math.html I read:
12
by: bsabiston | last post by:
Hi, I'm trying to get the fractional part of a floating point number. I've tried fmod() and modf(), and while both do work, they also occasionally return 1.0 for the fractional part of the number...
5
by: Tim Prince | last post by:
Bill Cunningham wrote: abs() is of type int; fabs() was of type double in C89 <math.h>, it may be in <tgmath.hif your compiler has some C99 capability. Most compilers can generate single...
6
by: Blue sky | last post by:
Hi ,I think the follow program is right in logical But why the compiler output :"square:declared identifier" #include<stdio.h> #include<math.h> int main() { double x1;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.