home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / text / 1086 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  1.6 KB

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!mips!sdd.hp.com!usc!rpi!batcomputer!munnari.oz.au!bruce.cs.monash.edu.au!goanna!minyos.xx.rmit.oz.au!kjb
  2. From: kjb@cgl.citri.edu.au (Kendall Bennett)
  3. Newsgroups: comp.text
  4. Subject: Re: Rounding function in c
  5. Message-ID: <kjb.712461189@godzilla.cgl.citri.edu.au>
  6. Date: 30 Jul 92 01:53:09 GMT
  7. References: <1992Jul14.181421.24591@mr.med.ge.com> <1992Jul16.232926.4740@rossinc.com> <451@rascal.UUCP>
  8. Sender: usenet@minyos.xx.rmit.oz.au (Njuiz noveles nova newes)
  9. Organization: RMIT Advanced Computer Graphics Centre, CITRI, Melbourne
  10. Lines: 29
  11.  
  12. theo@rascal.UUCP (1472) writes:
  13.  
  14. >> Does anyone out there have a rounding function for ANSI 'C', I am
  15. >>trying to do some financial applications, and badly need a rounding
  16. >>function.
  17.  
  18. This must be an FAQ, but you can do it with a simple macro or C++ inline
  19. function:
  20.  
  21. #define    ROUND(x)    (floor((x) + 0.5))
  22.  
  23. or
  24.  
  25. inline double round(double x)
  26. {
  27.     return floor(x + 0.5);
  28. }
  29.  
  30. Note that this is universal, and works correctly for both the positive AND
  31. negative cases of x.
  32.  
  33. +------------------------------------------+-------------------------------+
  34. | Kendall Bennett,                         | Internet:                     |
  35. | Advanced Computer Graphics Centre,       | kjb@godzilla.cgl.citri.edu.au |
  36. | Royal Melbourne Institute of Technology, | rcskb@minyos.xx.rmit.oz.au    |
  37. | Victoria, AUSTRALIA.                     |                               | 
  38. +------------------------------------------+-------------------------------+
  39. | CoSysop (Bossman), PC Connection Australia:               +61 3 688 0909 |
  40. +--------------------------------------------------------------------------+
  41.