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