home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16404 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.4 KB  |  42 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!spool.mu.edu!agate!doc.ic.ac.uk!mrccrc!warwick!coventry!champion
  3. From: champion@cch.coventry.ac.uk (Alun)
  4. Subject: Re: Rounding floats to integers
  5. Message-ID: <BxM0Eu.DxL@cck.coventry.ac.uk>
  6. Sender: news@cck.coventry.ac.uk (news user)
  7. Nntp-Posting-Host: cc_sysh
  8. Organization: Coventry University, Coventry, UK.
  9. References: <rfries.123@sceng.ub.com> <BxJx0s.6q8@cck.coventry.ac.uk> <BxK7xK.7Ap@sci.kun.nl>
  10. Date: Thu, 12 Nov 1992 15:30:29 GMT
  11. Lines: 29
  12.  
  13. In article <BxK7xK.7Ap@sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes:
  14. ~In <BxJx0s.6q8@cck.coventry.ac.uk> champion@cch.coventry.ac.uk (Alun) asks:
  15. ~
  16. ~>int round(float n)
  17. ~>{
  18. ~>    if(n < 0)
  19. ~>        return (int)(n - 0.5);    
  20. ~>    return (int)(n + 0.5);     // Doesn't the function do the cast automatically
  21. ~>}
  22. ~
  23. ~In C the fact that the function is declared to return an int makes the casts
  24. ~redundant.  I don't know about C++ (or whatever language it is that you use).
  25. ~Go and ask in the relevant group, if you really want to know.  Or look it up
  26. ~in a book.
  27.  
  28. This *is* C my apologies for the misleading comment.
  29. The comment should of been.
  30.  
  31. /* Doesn't the function do the cast automatically ?? */
  32.  
  33. You answered my question anyway.
  34.  
  35. Cheers
  36.  
  37.     -Alun
  38.     
  39. -- 
  40. A.Champion                |  That's an interesting point, in the sense of
  41. (champion@uk.ac.cov.cck)  |    being very not interesting at all. - The Liar
  42.