home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!spool.mu.edu!umn.edu!mmm.serc.3m.com!pwcs!cdsmn!wells
- From: wells@cdsmn.mn.org (Rich Wells)
- Subject: Re: the abs() function in C
- Message-ID: <By1DwJ.KKF@cdsmn.mn.org>
- Organization: Dicomed, Inc
- X-Newsreader: TIN [version 1.1 PL6]
- References: <maurer.722246649@magellan.stanford.edu>
- Date: Fri, 20 Nov 1992 22:45:54 GMT
- Lines: 23
-
- Michael Maurer (maurer@nova.stanford.edu) wrote:
- : In <pebi.722223424@zephyr.aem.umn.edu> pebi@aem.umn.edu (Peter A. Bidian) writes:
- :
- : >Isn't abs(-2)=2 in C?
- : >I always get 0.
-
- Your compiler sounds seriously broken. Care to let us know what
- compiler it is, so we can avoid it? (Some code showing how to
- reproduce the problem may be handy, too, in the outside chance
- that it is a cockpit error.)
-
- : you probably want to say abs(-2.0), if the abs() function expects a
- : floating point argument. or abs((double)-2).
-
- Wrong. abs() takes and integer argument, and returns an integer.
- (Thus, it should even work without including stdlib.h.) fabs()
- is the equivalent for floating point numbers. (And, just to be
- complete, labs() for long integers.) If the original poster's
- C compiler expects abs() to take a floating point argument, it is
- as seriously broken as if it returns 0 for abs(-2).
- --
-
- Richard Wells wells@cdsmn.mn.org or ...!tcnet!cdsmn!wells
-