Skip to content

Commit

Permalink
Evaluate int constants only once (fixes #861)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Feb 27, 2021
1 parent b995ab2 commit eac3d1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions l3kernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.

## [Unreleased]

### Fixed
- Evalutate integer constants only once (issue#861)

### Deprecated
- `l3docstrip` converted to a stub which simply loads DocStrip: use
the latter directly
Expand Down
16 changes: 10 additions & 6 deletions l3kernel/l3int.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@
% \end{macro}
%
% \begin{macro}{\int_const:Nn, \int_const:cn}
% \begin{macro}{\@@_const:nN}
% \begin{macro}{\@@_constdef:Nw}
% \begin{variable}{\c_@@_max_constdef_int}
% \UnitTested
Expand All @@ -1293,24 +1294,26 @@
% enabled) this runs some checks that constants would fail.
% \begin{macrocode}
\cs_new_protected:Npn \int_const:Nn #1#2
{ \exp_args:Ne \@@_const:nN { \int_eval:n {#2} } #1 }
\cs_new_protected:Npn \@@_const:nN #1#2
{
\int_compare:nNnTF {#2} < \c_zero_int
\int_compare:nNnTF {#1} < \c_zero_int
{
\int_new:N #1
\int_new:N #2
\tex_global:D
}
{
\int_compare:nNnTF {#2} > \c_@@_max_constdef_int
\int_compare:nNnTF {#1} > \c_@@_max_constdef_int
{
\int_new:N #1
\int_new:N #2
\tex_global:D
}
{
\__kernel_chk_if_free_cs:N #1
\__kernel_chk_if_free_cs:N #2
\tex_global:D \@@_constdef:Nw
}
}
#1 = \@@_eval:w #2 \@@_eval_end:
#2 = \@@_eval:w #1 \@@_eval_end:
}
\cs_generate_variant:Nn \int_const:Nn { c }
\if_int_odd:w 0
Expand All @@ -1329,6 +1332,7 @@
% \end{variable}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\int_zero:N, \int_zero:c}
% \UnitTested
Expand Down

0 comments on commit eac3d1d

Please sign in to comment.