~ubuntu-branches/ubuntu/hardy/luatex/hardy

« back to all changes in this revision

Viewing changes to src/texk/web2c/lib/zround.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2007-09-24 12:56:11 UTC
  • Revision ID: james.westby@ubuntu.com-20070924125611-a8ge689azbptxvla
Tags: upstream-0.11.2
ImportĀ upstreamĀ versionĀ 0.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* zround.c: round R to the nearest whole number.  This is supposed to
 
2
   implement the predefined Pascal round function.  Public domain. */
 
3
 
 
4
#include "config.h"
 
5
 
 
6
integer
 
7
zround P1C(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
     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).  */
 
27
  if (r > 2147483647.0)
 
28
    i = 2147483647;
 
29
  /* should be ...8, but atof bugs are too common */
 
30
  else if (r < -2147483647.0)
 
31
    i = -2147483647;
 
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.  */
 
35
  else if (r >= 0.0)
 
36
    i = (integer)(r + 0.5);
 
37
  else
 
38
    i = (integer)(r - 0.5);
 
39
 
 
40
  return i;
 
41
}