home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / lynxlib / round.c < prev    next >
Encoding:
Text File  |  1993-10-23  |  1.1 KB  |  37 lines

  1. /* This source file is part of the LynxLib miscellaneous library by
  2. Robert Fischer, and is Copyright 1990 by Robert Fischer.  It costs no
  3. money, and you may not make money off of it, but you may redistribute
  4. it.  It comes with ABSOLUTELY NO WARRANTY.  See the file LYNXLIB.DOC
  5. for more details.
  6. To contact the author:
  7.     Robert Fischer \\80 Killdeer Rd \\Hamden, CT   06517   USA
  8.     (203) 288-9599     fischer-robert@cs.yale.edu                 */
  9.  
  10. unsigned round_down(i, nearest)
  11. unsigned i;
  12. unsigned nearest;
  13. {
  14.     return i - (i % nearest);
  15. }
  16. /* ----------------------------------------------------------- */
  17. unsigned round_up(i, nearest)
  18. unsigned i;
  19. unsigned nearest;
  20. {
  21.     i += nearest - 1;
  22.     return i - (i % nearest);
  23. }
  24. /* ----------------------------------------------------------- */
  25. int roundup_div(a, b)
  26. /* Returns a/b rounded up */
  27. {
  28.     return (a + b - 1) / b;
  29. }
  30. /* ----------------------------------------------------------- */
  31. int round_div(a, b)
  32. /* Returns a/b rounded to nearest integer */
  33. {
  34.     return (a + b/2) / b;
  35. }
  36. /* ----------------------------------------------------------- */
  37.