home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / unixtex-6.1b-src.lha / unixtex-6.1b / web2c / lib / zround.c < prev   
Encoding:
C/C++ Source or Header  |  1993-11-08  |  745 b   |  34 lines

  1. /* zround.c: round R to the nearest whole number.  */
  2.  
  3. #include "config.h"
  4.  
  5. integer
  6. zround (r)
  7.     double r;
  8. {
  9.   integer i;
  10.  
  11.   /* R can be outside the range of an integer if glue is stretching or
  12.      shrinking a lot.  We can't do any better than returning the largest
  13.      or smallest integer possible in that case.  It doesn't seem to make
  14.      any practical difference.  Here is a sample input file which
  15.      demonstrates the problem, from phil@cs.arizona.edu:
  16.          \documentstyle{article}
  17.     \begin{document}
  18.     \begin{flushleft}
  19.     $\hbox{} $\hfill 
  20.     \filbreak
  21.     \eject
  22.   */
  23.   if (r > INTEGER_MAX)
  24.     i = INTEGER_MAX;
  25.   else if (r < INTEGER_MIN)
  26.     i = INTEGER_MIN;
  27.   else if (r >= 0.0)
  28.     i = r + 0.5;
  29.   else
  30.     i = r - 0.5;
  31.  
  32.   return i;
  33. }
  34.