home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / MATH_AUX.C < prev    next >
C/C++ Source or Header  |  1994-01-03  |  1KB  |  70 lines

  1. /*
  2. ** @(#)math_aux.c    06/18/93    Chris Ahlstrom
  3. **
  4. **    Additional useful math routines.
  5. */
  6.  
  7. #include "math_aux.h"
  8.  
  9.  
  10. /************************************************************************
  11. ** round
  12. ** iround
  13. **
  14. **    Takes a real number, and rounds it up to the next digit, then
  15. ** returns it as a long or an integer.
  16. **
  17. **    No error checking at all is done.  The commented-out version
  18. ** really screws up.
  19. **
  20. *************************************************************************/
  21.  
  22. long
  23. round
  24. (
  25.     double x
  26. )
  27. {
  28.     if (x > 0)
  29.     x += 0.5;
  30.     else if (x < 0)
  31.     x -= 0.5;
  32.     return((long) x);
  33. }
  34.  
  35. int
  36. iround
  37. (
  38.     double x
  39. )
  40. {
  41.     if (x > 0.0)
  42.     x += 0.5;
  43.     else if (x < 0.0)
  44.     x -= 0.5;
  45.     return((int) x);
  46. }
  47.  
  48. #ifdef BUGRIDDENCODE
  49. long
  50. round
  51. (
  52.     double x
  53. )
  54. {
  55.     if (x > 0)
  56.     {
  57.     x += 0.5;
  58.     if (x > (double) HUGE_LONG_INT)
  59.         x = 0.0;        /* to flag the overflow condition    */
  60.     }
  61.     else
  62.     {
  63.     x -= 0.5;
  64.     if (x < (double) LOW_LONG_INT)
  65.         x = 0.0;        /* to flag the underflow condition    */
  66.     }
  67.     return((long) x);
  68. }
  69. #endif
  70.