1
/* zround.c: round R to the nearest whole number. This is supposed to
2
implement the predefined Pascal round function. Public domain. */
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}
23
djb@silverton.berkeley.edu points out we should testing against
24
TeX's largest or smallest integer (32 bits), not the machine's. So
25
we might as well use a floating-point constant, and avoid potential
26
compiler bugs (also noted by djb, on BSDI). */
29
/* should be ...8, but atof bugs are too common */
30
else if (r < -2147483647.0)
32
/* Admittedly some compilers don't follow the ANSI rules of casting
33
meaning truncating toward zero; but it doesn't matter enough to do
34
anything more complicated here. */
36
i = (integer)(r + 0.5);
38
i = (integer)(r - 0.5);