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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
%%
%% This is file `l3intexpr.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3intexpr.dtx (with options: `package,trace')
%%
%%
%% EXPERIMENTAL CODE
%%
%% Do not distribute this file without also distributing the
%% source files specified above.
%%
%% Do not distribute a modified version of this file.
%%
%%
%% File: l3intexpr.dtx Copyright (C) 2009 LaTeX3 project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version. The latest version
%% of this license is in the file
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``expl3 bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%% http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%% Snapshots taken from the repository represent work in progress and may
%% not work or may contain conflicting material! We therefore ask
%% people _not_ to put them into distributions, archives, etc. without
%% prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
\RequirePackage{l3names}
\GetIdInfo$Id: l3intexpr.dtx 1086 2009-03-20 19:29:35Z morten $
{L3 Integer Expressions}
\ProvidesExplPackage
{\filename}{\filedate}{\fileversion}{\filedescription}
\package_check_loaded_expl:
\cs_set_eq:NN \intexpr_value:w \tex_number:D
\cs_set_eq:NN \intexpr_eval:w \etex_numexpr:D
\cs_set_protected:Npn \intexpr_eval_end: {\tex_relax:D}
\cs_set_eq:NN \if_intexpr_compare:w \tex_ifnum:D
\cs_set_eq:NN \if_intexpr_odd:w \tex_ifodd:D
\cs_set_eq:NN \if_intexpr_case:w \tex_ifcase:D
\cs_set:Npn \intexpr_eval:n #1{
\intexpr_value:w \intexpr_eval:w #1\intexpr_eval_end:
}
\prg_set_conditional:Npnn \intexpr_compare:n #1{p,TF,T,F}{
\exp_after:wN \intexpr_compare_auxi:w \intexpr_value:w
\intexpr_eval:w #1\q_stop
}
\cs_set:Npn \intexpr_compare_auxi:w #1#2\q_stop{
\exp_after:wN \intexpr_compare_auxii:w \tex_romannumeral:D
\if:w #1- \else: -\fi: #1#2 \q_stop #1#2 \q_nil
}
\cs_set:Npn \intexpr_compare_auxii:w #1#2#3\q_stop{
\use:c{
intexpr_compare_
#1 \if_meaning:w =#2 = \fi:
:w}
}
\cs_set:cpn {intexpr_compare_=:w} #1=#2\q_nil{
\if_intexpr_compare:w #1=\intexpr_eval:w #2 \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\cs_set:cpn {intexpr_compare_==:w} #1==#2\q_nil{
\if_intexpr_compare:w #1=\intexpr_eval:w #2 \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\cs_set:cpn {intexpr_compare_!=:w} #1!=#2\q_nil{
\if_intexpr_compare:w #1=\intexpr_eval:w #2 \intexpr_eval_end:
\prg_return_false: \else: \prg_return_true: \fi:
}
\cs_set:cpn {intexpr_compare_<:w} #1<#2\q_nil{
\if_intexpr_compare:w #1<\intexpr_eval:w #2 \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\cs_set:cpn {intexpr_compare_>:w} #1>#2\q_nil{
\if_intexpr_compare:w #1>\intexpr_eval:w #2 \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\cs_set:cpn {intexpr_compare_<=:w} #1<=#2\q_nil{
\if_intexpr_compare:w #1<\intexpr_eval:w #2 +\c_one \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\cs_set:cpn {intexpr_compare_>=:w} #1>=#2\q_nil{
\if_intexpr_compare:w #1>\intexpr_eval:w #2 - \c_one \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\prg_set_conditional:Npnn \intexpr_compare:nNn #1#2#3{p,TF,T,F}{
\if_intexpr_compare:w \intexpr_eval:w #1 #2 \intexpr_eval:w #3 \intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\cs_set:Npn \intexpr_abs:n #1{
\intexpr_value:w
\if_intexpr_compare:w \intexpr_eval:w #1<\c_zero
-
\fi:
\intexpr_eval:w #1\intexpr_eval_end:
}
\cs_set:Npn \intexpr_max:nn #1#2{
\intexpr_value:w \intexpr_eval:w
\if_intexpr_compare:w
\intexpr_eval:w #1>\intexpr_eval:w #2\intexpr_eval_end:
#1
\else:
#2
\fi:
\intexpr_eval_end:
}
\cs_set:Npn \intexpr_min:nn #1#2{
\intexpr_value:w \intexpr_eval:w
\if_intexpr_compare:w
\intexpr_eval:w #1<\intexpr_eval:w #2\intexpr_eval_end:
#1
\else:
#2
\fi:
\intexpr_eval_end:
}
\cs_set:Npn \intexpr_div_truncate:nn #1#2 {
\intexpr_value:w \intexpr_eval:w
\if_intexpr_compare:w \intexpr_eval:w #1 = \c_zero
0
\else:
(#1
\if_intexpr_compare:w \intexpr_eval:w #1 < \c_zero
\if_intexpr_compare:w \intexpr_eval:w #2 < \c_zero
-( #2 +
\else:
+( #2 -
\fi:
\else:
\if_intexpr_compare:w \intexpr_eval:w #2 < \c_zero
+( #2 +
\else:
-( #2 -
\fi:
\fi:
1)/2)
\fi:
/(#2)
\intexpr_eval_end:
}
\cs_set:Npn \intexpr_div_round:nn #1#2 {\intexpr_eval:n{(#1)/(#2)}}
\cs_set:Npn \intexpr_mod:nn #1#2 {
\intexpr_value:w
\intexpr_eval:w
#1 - \intexpr_div_truncate:nn {#1}{#2} * (#2)
\intexpr_eval_end:
}
\prg_set_conditional:Npnn \intexpr_if_odd:n #1 {p,TF,T,F} {
\if_intexpr_odd:w \intexpr_eval:w #1\intexpr_eval_end:
\prg_return_true: \else: \prg_return_false: \fi:
}
\prg_set_conditional:Npnn \intexpr_if_even:n #1 {p,TF,T,F} {
\if_intexpr_odd:w \intexpr_eval:w #1\intexpr_eval_end:
\prg_return_false: \else: \prg_return_true: \fi:
}
\cs_set:Npn \intexpr_while_do:nn #1#2{
\intexpr_compare:nT {#1}{#2 \intexpr_while_do:nn {#1}{#2}}
}
\cs_set:Npn \intexpr_until_do:nn #1#2{
\intexpr_compare:nF {#1}{#2 \intexpr_until_do:nn {#1}{#2}}
}
\cs_set:Npn \intexpr_do_while:nn #1#2{
#2 \intexpr_compare:nT {#1}{\intexpr_do_while:nNnn {#1}{#2}}
}
\cs_set:Npn \intexpr_do_until:nn #1#2{
#2 \intexpr_compare:nF {#1}{\intexpr_do_until:nn {#1}{#2}}
}
\cs_set:Npn \intexpr_while_do:nNnn #1#2#3#4{
\intexpr_compare:nNnT {#1}#2{#3}{#4 \intexpr_while_do:nNnn {#1}#2{#3}{#4}}
}
\cs_set:Npn \intexpr_until_do:nNnn #1#2#3#4{
\intexpr_compare:nNnF {#1}#2{#3}{#4 \intexpr_until_do:nNnn {#1}#2{#3}{#4}}
}
\cs_set:Npn \intexpr_do_while:nNnn #1#2#3#4{
#4 \intexpr_compare:nNnT {#1}#2{#3}{\intexpr_do_while:nNnn {#1}#2{#3}{#4}}
}
\cs_set:Npn \intexpr_do_until:nNnn #1#2#3#4{
#4 \intexpr_compare:nNnF {#1}#2{#3}{\intexpr_do_until:nNnn {#1}#2{#3}{#4}}
}
%%
%%
%% End of file `l3intexpr.sty'.
|