blob: 23d484028735c82fdbc4c530dd346434848cc6a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
\newcount\@temp@inti
\newcount\@temp@intii
\addassoc\@globalenv\+{\@tlabel@func{\@temp@inti0\relax\@arith@plus}}
\def\@arith@plus#1#2#3{%
\ifx#2\relax
\let\@next@plus\@@arith@pm@fin
\else\ifx#2\@tlabel@int
\advance\@temp@inti#3\relax
\let\@next@plus\@arith@plus
\else
\errmessage{LISP on TeX [integer plus]: Invalid argument}%
\fi\fi\@next@plus#1}
\addassoc\@globalenv\*{\@tlabel@func{\@temp@inti1\relax\@arith@mul}}
\def\@arith@mul#1#2#3{%
\ifx#2\relax
\let\@next@mul\@@arith@pm@fin
\else\ifx#2\@tlabel@int
\multiply\@temp@inti#3\relax
\let\@next@mul\@arith@mul
\fi\fi\@next@mul#1}
\def\@@arith@pm@fin#1{\expandafter\gdef
\expandafter#1\expandafter{%
\expandafter\@tlabel@int\expandafter{\the\@temp@inti}}}
\addassoc\@globalenv\-{\@tlabel@func{\@arith@minus}}
\def\@arith@minus#1#2#3#4#5{%
\@temp@inti#3\relax
\ifx#4\relax
\multiply\@temp@inti-1\relax
\let\@next@minus\@@arith@pm@fin
\else\ifx#4\@tlabel@int
\let\@next@minus\@@arith@minus
\fi\fi\@next@minus#1#4{#5}}
\def\@@arith@minus#1#2#3{%
\ifx#2\relax
\let\@next@minus\@@arith@pm@fin
\else\ifx#2\@tlabel@int
\@temp@intii#3\relax % #3 < 0
\advance\@temp@inti-\@temp@intii\relax
\let\@next@minus\@@arith@minus
\fi\fi\@next@minus#1}
\addassoc\@globalenv\/{\@tlabel@func{\@arith@div}}
\def\@arith@div#1#2#3#4#5{%
\@temp@inti#3\relax
\ifx#4\relax
\@temp@intii\@temp@inti\relax
\@temp@inti1\relax
\divide\@temp@inti\@temp@intii\relax
\let\@next@div\@@arith@pm@fin
\else\ifx#4\@tlabel@int
\let\@next@div\@@arith@div
\fi\fi\@next@div#1#4{#5}}
\def\@@arith@div#1#2#3{%
\ifx#2\relax
\let\@next@div\@@arith@pm@fin
\else\ifx#2\@tlabel@int
\divide\@temp@inti#3\relax
\let\@next@div\@@arith@div
\fi\fi\@next@div#1}
\addassoc\@globalenv\mod{\@tlabel@func{\@arith@mod}}
\def\@arith@mod#1\@tlabel@int#2\@tlabel@int#3{%
\@temp@intii#2\relax
\divide\@temp@intii#3\relax
\multiply\@temp@intii#3\relax
\@temp@inti#2\relax
\advance\@temp@inti-\@temp@intii
\@@arith@pm@fin#1}
\addassoc\@globalenv\<{\@tlabel@func{\@arith@lt}}
\def\@arith@lt#1\@tlabel@int#2\@tlabel@int#3{%
\ifnum#2<#3 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
\addassoc\@globalenv\>{\@tlabel@func{\@arith@gt}}
\def\@arith@gt#1\@tlabel@int#2\@tlabel@int#3{%
\ifnum#2>#3 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
\addassoc\@globalenv\leq{\@tlabel@func{\@arith@leq}}
\def\@arith@leq#1\@tlabel@int#2\@tlabel@int#3{%
\ifnum#2<#3 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi
\ifnum#2=#3 \gdef#1{\@tlabel@bool{t}}\fi}
\addassoc\@globalenv\geq{\@tlabel@func{\@arith@geq}}
\def\@arith@geq#1\@tlabel@int#2\@tlabel@int#3{%
\ifnum#2>#3 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi
\ifnum#2=#3 \gdef#1{\@tlabel@bool{t}}\fi}
\addassoc\@globalenv\isZeroQ{\@tlabel@func{\@arith@is@zero}}
\def\@arith@is@zero#1\@tlabel@int#2{%
\ifnum#2=0 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
\addassoc\@globalenv\positiveQ{\@tlabel@func{\@arith@is@positive}}
\def\@arith@is@positive#1\@tlabel@int#2{%
\ifnum#2>0 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
\addassoc\@globalenv\negativeQ{\@tlabel@func{\@arith@is@negative}}
\def\@arith@is@positive#1\@tlabel@int#2{%
\ifnum#2<0 \gdef#1{\@tlabel@bool{t}}\else\gdef#1{\@tlabel@bool{f}}\fi}
\addassoc\@globalenv\max{\@tlabel@func{\@arith@max}}
\def\@arith@max#1#2#3{%
\ifx#2\@tlabel@int
\@temp@inti#3\relax
\let\@next@max\@@arith@max
\else
\errmessage{LISP on TeX [integer max]: Invalid argument or Too few arguments}%
\fi\@next@max#1}
\def\@@arith@max#1#2#3{%
\ifx#2\relax
\let\@next@max\@@arith@pm@fin
\else\ifx#2\@tlabel@int
\ifnum#3>\@temp@inti\@temp@inti#3\relax\fi
\let\@next@max\@@arith@max
\else
\errmessage{LISP on TeX [integer max]: Invalid argument}%
\fi\fi\@next@max#1}
\addassoc\@globalenv\min{\@tlabel@func{\@arith@min}}
\def\@arith@min#1#2#3{%
\ifx#2\@tlabel@int
\@temp@inti#3\relax
\let\@next@min\@@arith@min
\else
\errmessage{LISP on TeX [integer min]: Invalid argument or Too few arguments}%
\fi\@next@min#1}
\def\@@arith@min#1#2#3{%
\ifx#2\relax
\let\@next@min\@@arith@pm@fin
\else\ifx#2\@tlabel@int
\ifnum#3<\@temp@inti\@temp@inti#3\relax\fi
\let\@next@min\@@arith@min
\else
\errmessage{LISP on TeX [integer min]: Invalid argument}%
\fi\fi\@next@min#1}
|