diff options
author | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
commit | ad547a6b5986815fda458221149728d9d9ab1d87 (patch) | |
tree | 16296910eb3eca724371474ea9aea3994dc69614 /Build/source/texk/web2c/lib/zround.c | |
parent | 947b43de3dd21d58ccc2ffadefc4441ea1c2a813 (diff) |
restore Build,TODO from r57911
git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/lib/zround.c')
-rw-r--r-- | Build/source/texk/web2c/lib/zround.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/lib/zround.c b/Build/source/texk/web2c/lib/zround.c new file mode 100644 index 00000000000..e51eed8fa2a --- /dev/null +++ b/Build/source/texk/web2c/lib/zround.c @@ -0,0 +1,42 @@ +/* zround.c: round R to the nearest whole number. This is supposed to + implement the predefined Pascal round function. Public domain. */ + +#include <w2c/config.h> +#include "lib.h" + +integer +zround (double r) +{ + integer i; + + /* R can be outside the range of an integer if glue is stretching or + shrinking a lot. We can't do any better than returning the largest + or smallest integer possible in that case. It doesn't seem to make + any practical difference. Here is a sample input file which + demonstrates the problem, from phil@cs.arizona.edu: + \documentstyle{article} + \begin{document} + \begin{flushleft} + $\hbox{} $\hfill + \filbreak + \eject + + djb@silverton.berkeley.edu points out we should testing against + TeX's largest or smallest integer (32 bits), not the machine's. So + we might as well use a floating-point constant, and avoid potential + compiler bugs (also noted by djb, on BSDI). */ + if (r > 2147483647.0) + i = 2147483647; + /* should be ...8, but atof bugs are too common */ + else if (r < -2147483647.0) + i = -2147483647; + /* Admittedly some compilers don't follow the ANSI rules of casting + meaning truncating toward zero; but it doesn't matter enough to do + anything more complicated here. */ + else if (r >= 0.0) + i = (integer)(r + 0.5); + else + i = (integer)(r - 0.5); + + return i; +} |