home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16903 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.4 KB

  1. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  2. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: the abs() function in C
  5. Message-ID: <1992Nov20.202243.27645@klaava.Helsinki.FI>
  6. Date: 20 Nov 92 20:22:43 GMT
  7. References: <pebi.722223424@zephyr.aem.umn.edu> <maurer.722246649@magellan.stanford.edu>
  8. Organization: University of Helsinki
  9. Lines: 23
  10.  
  11. maurer@nova.stanford.edu (Michael Maurer) writes:
  12. >>Isn't abs(-2)=2 in C? I always get 0.
  13. >
  14. >you probably want to say abs(-2.0), if the abs() function expects a
  15. >floating point argument.  or abs((double)-2).
  16.  
  17. As the quickest of glances at the friendly manual will tell you, abs
  18. does not expect a floating point argument, it expects an integer.  Use
  19. fabs for floating point.
  20.  
  21. I do not know what causes the trouble for the original poster.  It
  22. could have been invalid code (he did not show any actual code),
  23. invalid compilation.  It could be an error in the compiler or
  24. libraries, but somehow I doubt that: abs is far too easy to get right.
  25.  
  26. If the original poster has not solved his problem yet, perhaps he
  27. should ask again, this time giving a small (preferably less than 10
  28. lines) but still complete (preferably a complete program) example of
  29. source code that shows the problem.
  30.  
  31. --
  32. Lars.Wirzenius@helsinki.fi  (finger wirzeniu@klaava.helsinki.fi)
  33.    MS-DOS, you can't live with it, you can live without it.
  34.