beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / tex / arithmetic.h
blobe5638990e0c728d99bc657502a1b0a4172551792
1 /* arithmetic.h
3 Copyright 2009 Taco Hoekwater <taco@luatex.org>
5 This file is part of LuaTeX.
7 LuaTeX is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
12 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License along
18 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
21 #ifndef ARITHMETIC_H
22 # define ARITHMETIC_H
24 /* |incr| and |decr| are in texmfmp.h */
26 /* #define incr(A) (A)++ *//* increase a variable by unity */
27 /* #define decr(A) (A)-- *//* decrease a variable by unity */
29 # define negate(A) (A)=-(A) /* change the sign of a variable */
31 # undef half
32 extern int half(int x);
35 Fixed-point arithmetic is done on {\sl scaled integers\/} that are multiples
36 of $2^{-16}$. In other words, a binary point is assumed to be sixteen bit
37 positions from the right end of a binary computer word.
40 # define unity 0200000 /* $2^{16}$, represents 1.00000 */
41 # define two 0400000 /* $2^{17}$, represents 2.00000 */
43 typedef unsigned int nonnegative_integer; /* $0\L x<2^{31}$ */
45 extern scaled round_decimals(int k);
46 extern void print_scaled(scaled s);
48 extern boolean arith_error;
49 extern scaled tex_remainder;
51 extern scaled mult_and_add(int n, scaled x, scaled y, scaled max_answer);
53 # define nx_plus_y(A,B,C) mult_and_add((A),(B),(C),07777777777)
54 # define mult_integers(A,B) mult_and_add((A),(B),0,017777777777)
56 extern scaled x_over_n(scaled x, int n);
57 extern scaled xn_over_d(scaled x, int n, int d);
59 # define inf_bad 10000 /* infinitely bad value */
61 extern halfword badness(scaled t, scaled s);
63 # define set_glue_ratio_zero(A) (A)=0.0 /* store the representation of zero ratio */
64 # define set_glue_ratio_one(A) (A)=1.0 /* store the representation of unit ratio */
65 # define float_cast(A) (float)(A) /* convert from |glue_ratio| to type |real| */
66 # define unfloat(A) (glue_ratio)(A) /* convert from |real| to type |glue_ratio| */
67 # define float_constant(A) (float)A /* convert |integer| constant to |real| */
68 # define float_round round
70 extern void initialize_arithmetic(void);
72 extern scaled random_seed; /* the default random seed */
74 extern void init_randoms(int seed);
75 extern int unif_rand(int x);
76 extern int norm_rand(void);
78 extern int fix_int(int val, int min, int max);
80 #endif