home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16942 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.3 KB  |  35 lines

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