1 /* zround.c: round R to the nearest whole number. This is supposed to
2 implement the predefined Pascal round function. Public domain. */
4 #include <w2c/config.h>
12 /* R can be outside the range of an integer if glue is stretching or
13 shrinking a lot. We can't do any better than returning the largest
14 or smallest integer possible in that case. It doesn't seem to make
15 any practical difference. Here is a sample input file which
16 demonstrates the problem, from phil@cs.arizona.edu:
17 \documentstyle{article}
24 djb@silverton.berkeley.edu points out we should testing against
25 TeX's largest or smallest integer (32 bits), not the machine's. So
26 we might as well use a floating-point constant, and avoid potential
27 compiler bugs (also noted by djb, on BSDI). */
30 /* should be ...8, but atof bugs are too common */
31 else if (r
< -2147483647.0)
33 /* Admittedly some compilers don't follow the ANSI rules of casting
34 meaning truncating toward zero; but it doesn't matter enough to do
35 anything more complicated here. */
37 i
= (integer
)(r
+ 0.5);
39 i
= (integer
)(r
- 0.5);