473,387 Members | 1,942 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,387 software developers and data experts.

why is abs function complaining about double?

using g++ in cygwin...

sv.cpp:13: warning: passing `double' for converting 1 of `int abs(int)'

extract...

#include <stdlib.h>
#include <Math.h>

double pythag(double a, double b)
{
double absa, absb, tmp;

absa = abs(a); // this is line 13, where is the int?
absb = abs(b);
Thanks,
Daniel

Jul 23 '05 #1
6 15374
If you use stdlib.h abs(): taht has a int as argument, for a double you
use fabs()

Jul 23 '05 #2
sa************@hotmail.com wrote:
using g++ in cygwin...

sv.cpp:13: warning: passing `double' for converting 1 of `int abs(int)'

extract...

#include <stdlib.h> <cstdlib> would be better. #include <Math.h> <cmath> would be better. (and there it's math.h, not Math.h in any case).
double pythag(double a, double b)
{
double absa, absb, tmp;

absa = abs(a); // this is line 13, where is the int?
In the signature for abs(), of course! IF your argument is a double, you
want std::fabs().
absb = abs(b);


Similarly.

HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #3
<sa************@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
using g++ in cygwin...

sv.cpp:13: warning: passing `double' for converting 1 of `int abs(int)'

extract...

#include <stdlib.h>
#include <Math.h>

double pythag(double a, double b)
{
double absa, absb, tmp;

absa = abs(a); // this is line 13, where is the int?
absb = abs(b);


g++ under cygwin doesn't fully conform to the C++ Standard,
a problem with many implementations in this area. The C++
Standard requires a number of extensions to the C library,
which the C library maintainers often choose not to do and
the C++ library maintainers don't have permission to do.

Dinkumware supplies both libraries, so this program works
fine with our C/C++ library.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 23 '05 #4
P.J. Plauger wrote:
<sa************@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
using g++ in cygwin...

sv.cpp:13: warning: passing `double' for converting 1 of `int abs(int)'

extract...

#include <stdlib.h>
#include <Math.h>

double pythag(double a, double b)
{
double absa, absb, tmp;

absa = abs(a); // this is line 13, where is the int?
absb = abs(b);


g++ under cygwin doesn't fully conform to the C++ Standard,
a problem with many implementations in this area. The C++
Standard requires a number of extensions to the C library,
which the C library maintainers often choose not to do and
the C++ library maintainers don't have permission to do.

Dinkumware supplies both libraries, so this program works
fine with our C/C++ library.


P.J.: [I hope the salutation is appropriate]

Could you expand on this a little bit? Is it that abs() is supposed to
be overloaded to take/return doubles? (And wouldn't <cmath> need to be
included to get that behavior in any case?)

Many thanks,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #5
"Artie Gold" <ar*******@austin.rr.com> wrote in message
news:3i************@individual.net...
P.J. Plauger wrote:
<sa************@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
using g++ in cygwin...

sv.cpp:13: warning: passing `double' for converting 1 of `int abs(int)'

extract...

#include <stdlib.h>
#include <Math.h>

double pythag(double a, double b)
{
double absa, absb, tmp;

absa = abs(a); // this is line 13, where is the int?
absb = abs(b);
g++ under cygwin doesn't fully conform to the C++ Standard,
a problem with many implementations in this area. The C++
Standard requires a number of extensions to the C library,
which the C library maintainers often choose not to do and
the C++ library maintainers don't have permission to do.

Dinkumware supplies both libraries, so this program works
fine with our C/C++ library.


P.J.: [I hope the salutation is appropriate]


Work fine, thanks.
Could you expand on this a little bit? Is it that abs() is supposed to be
overloaded to take/return doubles?
Yes, and quite a few other types:

-- <math.h> adds overloads for float, double, and long double
-- <stdlib.h> adds an overload for long
-- <complex> adds overloads for all complex<T>
-- <valarray> adds overloads for all valarray<T>
(And wouldn't <cmath> need to be
included to get that behavior in any case?)


Nope. The C++ Standard effectively says:

1) The Standard C headers <xxx.h> are no longer fundamental.
Instead, the new Standard C++ headers <cxxx> define all the
old C stuff, plus a mess of overloads for abs and other
functions, in namespace std.

2) The revised <xxx.h> headers simply include their
corresponding <cxxx> versions, then hoist all the defined
names into the global namespace with using declarations.

Thus, including <math.h> should define abs(float),
abs(double), and abs(long double). You can pull this
off without performing the full inversion I describe
above, but it still requires substantial changes to
the C header files.

C compilers have been around for upwards of 35 years now.
Well over 100 different C libraries have evolved over
that period, each accumulating its own history of
proprietary extensions used by a large and growing
base of system and user code. These days, it is not
uncommon for the C library to be maintained by a group
that is quite independent of the C++ maintainers, a
group with a different development schedule and many
more constituencies than just C++ programmers.

The C++ people inside a large enterprise can usually
get chunks of code added to existing C headers,
preferably inside #ifdef __cpluplus/#endif wrappers.
But they have no chance, politically or technically,
of completely usurping the fundamental role of the
C development environment. Third-party C++ library
suppliers have it even worse -- they can make *no*
changes to existing C headers, and they have little
chance of completely replacing those headers and
replicating all the idiosyncracies of each system.

The C++ library that comes with gcc is effectively
a third-party library, since it sits atop several
different C libraries each maintained by other groups.
STLport, SGI/STL and the other bolt-on C++ libraries
suffer the same problem. The glibc folk, who provide
the Linux library, have been openly antagonistic to
C++. So you will find few of the extensions to C
mandated by the C++ Standard where they're needed
inside the <xxx.h> headers.

The nonstandard trick is to put the extensions just
inside the <cxxx> headers. Programmers who make a
point of using the <cxxx> headers are content, but
people like the OP in this thread get brought up
short.

Dinkumware is in a different position from other
third-party vendors:

1) We have a number of OEM customers, Microsoft the
most widely used among them, who ship our C++ library
atop their existing C library. Either we modify their
C library headers as needed for them, or we show them
what to pick up from our C headers, to provide much
better conformance. (There are still minor issues about
namespaces, but that's a whole 'nother topic.)

2) We have other OEM customers who ship both our C
and C++ libraries. They can fully conform, if they
choose. (Why they might choose not to fully conform
is yet another topic.)

3) We license our libraries directly to end users.
They can configure our C++ library to work "native"
atop an existing C library or with our C library
included in the package. The native configuration
is less conforming, but mixes better with older code.
By using our C library, you can be completely
conforming and better support applications intended
to be portable.

There have been many discussions of the limited support
for "export". Seven years after formal approval of the
C++ Standard, only compilers that use the Edison
Design Group front end (and the Dinkumware libraries)
have a chance at 100 per cent conformance. But the
C library changes required by the C++ Standard cause
much wider conformance problems. They're just less
sexy than template issues, I suppose.

Both conformance shortfalls have occurred because the
C++ committee insisted on overreaching, despite plenty
of warnings. I only hope that the next revision of the
C++ Standard fixes some of these problems and doesn't
add new ones.

HTH,

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 23 '05 #6
Wow, C/C++ has become so complicated, perhaps I might be better off
with a newer language. But I don't like java or C#.NET. What is a
good standard and compiler to use for cross platform development?
Dinkumware and MsVS? How long does the entry version last? What is
GBin and GSrc?

Jul 23 '05 #7

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

Similar topics

3
by: Matthew Sims | last post by:
Hey all, So I started using nl2br and love it. But when I convert back from <br> to \n, it produces double spaces instead of single space. Converting \n to <br>: $emailBody=nl2br($_POST);...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
0
by: Christopher Sin | last post by:
Hi, First, if I am on a wrong group, please tell me, therefore, i think this one is correct. Second, please ignore my poor English speaking. I have to write a c# wrapper to a C library....
2
by: Bruce D | last post by:
I'm calling another .exe in my program. The .exe needs 1 parameter and it needs double quotes around it. I can't figure this simple one out...can you help? Dim objRS2 As New Process...
21
by: Karl O. Pinc | last post by:
FYI, It'd be nice if the error message from a REFERENCES constraint mentioned the column name into which the bad data was attempted to be inserted. In PostgreSQL 7.3: sandbox=> insert into...
0
by: Glen Parker | last post by:
> I think in 7.2 such conversions were allowed silently, but we > have reduced the number of implicit type coercions. I'm sensing some brain damage going on here... DB=# select round(100::int,...
0
by: Marcel Boscher | last post by:
Hello everybody, i get strange error messages when trying to call up my function with a SELECT functionname(with or without int); varying from: ERROR: function chr(double precision) does...
4
by: B. Williams | last post by:
I have written this program for an assignment that requires a static member function to set a static data member, but I can't figure out how to get it to change the value once set. Would someone...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.