home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!sun4nl!sci.kun.nl!cs.kun.nl!hansm
- From: hansm@cs.kun.nl (Hans Mulder)
- Subject: Re: Rounding floats to integers
- Message-ID: <BxK7xK.7Ap@sci.kun.nl>
- Sender: news@sci.kun.nl (NUnet News Owner)
- Organization: University of Nijmegen, The Netherlands
- References: <92314.134711IA8@psuvm.psu.edu> <rfries.123@sceng.ub.com> <BxJx0s.6q8@cck.coventry.ac.uk>
- Date: Wed, 11 Nov 1992 16:17:43 GMT
- Lines: 18
-
- In <BxJx0s.6q8@cck.coventry.ac.uk> champion@cch.coventry.ac.uk (Alun) asks:
-
- >int round(float n)
- >{
- > if(n < 0)
- > return (int)(n - 0.5);
- > return (int)(n + 0.5); // Doesn't the function do the cast automatically
- >}
-
- In C the fact that the function is declared to return an int makes the casts
- redundant. I don't know about C++ (or whatever language it is that you use).
- Go and ask in the relevant group, if you really want to know. Or look it up
- in a book.
-
- --
- Hope this helps,
-
- Hans Mulder hansm@cs.kun.nl
-