summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/xint/xintexpr.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/xint/xintexpr.sty')
-rw-r--r--Master/texmf-dist/tex/generic/xint/xintexpr.sty1112
1 files changed, 697 insertions, 415 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintexpr.sty b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
index 45378ace18a..3c1de7ed8a9 100644
--- a/Master/texmf-dist/tex/generic/xint/xintexpr.sty
+++ b/Master/texmf-dist/tex/generic/xint/xintexpr.sty
@@ -22,7 +22,7 @@
%% in the same archive or directory.)
%%
%%----------------------------------------------------------------
-%% The xint bundle (version 1.08b of June 14, 2013)
+%% The xint bundle (version 1.09a of September 22, 2013)
%% xintexpr: Expandable expression parser
%% Copyright (C) 2013 by Jean-Francois Burnol
%%----------------------------------------------------------------
@@ -114,6 +114,10 @@
\endgroup
\edef\XINT_expr_restorecatcodes_endinput
{%
+ \catcode63=\the\catcode63 % ?
+ \catcode124=\the\catcode124 % |
+ \catcode38=\the\catcode38 % &
+ \catcode64=\the\catcode64 % @
\catcode33=\the\catcode33 % !
\catcode93=\the\catcode93 % ]
\catcode91=\the\catcode91 % [
@@ -141,14 +145,17 @@
\noexpand\endinput
}%
\XINT_setcatcodes % defined in xint.sty
- \catcode91=12 % [
- \catcode93=12 % ]
- \catcode33=11 % !
+ \catcode91=12 % [
+ \catcode93=12 % ]
+ \catcode33=11 % !
+ \catcode64=11 % @
+ \catcode38=12 % &
+ \catcode124=12 % |
+ \catcode63=11 % ?
}%
\x
\begingroup
- \catcode64=11 % @
- \catcode58=12 % :
+ \catcode58=12 % : (but doesn't matter)
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
\def\x#1#2#3[#4]{\endgroup
\immediate\write-1{Package: #3 #4}%
@@ -167,191 +174,40 @@
\fi
\expandafter\x\csname ver@xintexpr.sty\endcsname
\ProvidesPackage{xintexpr}%
- [2013/06/14 v1.08b Expandable expression parser (jfB)]%
+ [2013/09/24 v1.09a Expandable expression parser (jfB)]%
\def\xint_gob_til_dot #1.{}%
\def\xint_gob_til_dot_andstop #1.{ }%
-\def\xint_gob_til_! #1!{}% ! of catcode 11
-\def\XINT_expr_string {\expandafter\xint_gob_til_dot\string }%
+\def\xint_gob_til_! #1!{}% nota bene: ! is of catcode 11
\def\XINT_expr_unexpectedtoken {\xintError:ignored }%
-\def\xintexpr {\romannumeral0\xinteval }%
+\def\XINT_newexpr_stripprefix #1>{\noexpand\romannumeral-`0}%
+\def\xint_firstofone #1{#1}%
+\def\XINT_expr_lock #1!{\expandafter\space\csname .#1\endcsname }%
+\def\XINT_expr_unlock {\expandafter\xint_gob_til_dot\string }%
+\def\XINT_expr_usethe {use_xintthe!\xintError:use_xintthe! }%
+\def\XINT_expr_done {!\XINT_expr_usethe\XINT_expr_print }%
+\def\XINT_expr_print #1{\XINT_expr_unlock #1}%
+\def\XINT_flexpr_done {!\XINT_expr_usethe\XINT_flexpr_print }%
+\def\XINT_flexpr_print #1{\xintFloat:csv{\XINT_expr_unlock #1}}%
+\def\XINT_numexpr_print #1{\xintRound:csv{\XINT_expr_unlock #1}}%
+\def\xintexpr {\romannumeral0\xinteval }%
\def\xinteval
{%
- \expandafter\XINT_expr_until_end\romannumeral-`0%
- \expandafter\XINT_expr_checkifprefix_ii\romannumeral-`0%
- \XINT_expr_getnext
-}%
-\def\xinttheexpr {\romannumeral0\xinttheeval }%
-\def\xinttheeval {\expandafter\XINT_expr_the\romannumeral0\xinteval }%
-\def\XINT_expr_the #1#2#3{\xintraw{\XINT_expr_string #3}}%
-\def\xintthe #1{\ifx#1\xintexpr \expandafter\xinttheexpr
- \else\expandafter\xintthefloatexpr\fi}%
-\def\XINT_expr_until_end #1%
-{%
- \ifcase#1%
- \expandafter\xint_gobble_vi
- \or
- \expandafter\XINT_expr_extra_closing_paren
- \fi
- \expandafter\XINT_expr_until_end\romannumeral-`0\romannumeral-`0%
-}%
-\def\XINT_expr_extra_closing_paren {\xintError:removed }%
-\def\XINT_expr_endofexpr {!\XINT_illegaluse }%
-\def\XINT_illegaluse
- {Illegal_here_use_xintthe\xintError:use_xintthe!\xint_gobble_i }%
-\def\XINT_expr_oparen
-{%
- \expandafter\XINT_expr_until_cparen\romannumeral-`0%
- \expandafter\XINT_expr_checkifprefix_ii\romannumeral-`0%
- \XINT_expr_getnext
-}%
-\def\XINT_expr_until_cparen #1%
-{%
- \ifcase#1%
- \expandafter\XINT_expr_missing_cparen
- \or
- \else \xint_afterfi
- {\expandafter\XINT_expr_until_cparen\romannumeral-`0\romannumeral-`0}%
- \fi
-}%
-\def\XINT_expr_missing_cparen #1%
-{%
- \xintError:inserted \xint_c_ \XINT_expr_endofexpr
-}%
-\def\xint_tmp_def #1#2#3%
-{%
- \expandafter\xint_tmp_do_defs
- \csname XINT_expr_op_#1\expandafter\endcsname
- \csname XINT_expr_until_#1\expandafter\endcsname
- \csname XINT_expr_checkifprefix_#2\expandafter\endcsname
- \csname XINT_expr_precedence_#1\expandafter\endcsname
- \csname xint_c_#2\expandafter\endcsname
- \csname xint#3\endcsname
-}%
-\def\xint_tmp_do_defs #1#2#3#4#5#6%
-{%
- \def #1##1% \XINT_expr_op_?
- {%
- \expandafter #2\expandafter ##1\romannumeral-`0\expandafter
- #3\romannumeral-`0\XINT_expr_getnext
- }%
- \def #2##1##2##3##4% \XINT_expr_until_?
- {%
- \ifnum ##2>#5%
- \xint_afterfi {\expandafter #2\expandafter ##1\romannumeral-`0##3##4}%
- \else
- \xint_afterfi
- {\expandafter ##2\expandafter ##3%
- \csname .#6{\XINT_expr_string ##1}{\XINT_expr_string ##4}\endcsname }%
- \fi
- }%
- \let #4#5%
-}%
-\xint_tmp_def +{ii}{Add}%
-\xint_tmp_def -{ii}{Sub}%
-\xint_tmp_def *{iii}{Mul}%
-\xint_tmp_def /{iii}{Div}%
-\xint_tmp_def ^{iv}{Pow}%
-\xint_tmp_def e{v}{fE}%
-\xint_tmp_def E{v}{fE}%
-\def\xint_tmp_def #1%
-{%
- \expandafter\xint_tmp_do_defs
- \csname XINT_expr_checkifprefix_#1\expandafter\endcsname
- \csname XINT_expr_op_-#1\endcsname
-}%
-\def\xint_tmp_do_defs #1#2%
-{%
- \def #1##1%
- {\xint_UDsignfork
- ##1\dummy #2%
- -\dummy ##1%
- \krof }%
-}%
-\xint_tmp_def {ii}%
-\xint_tmp_def {iii}%
-\xint_tmp_def {iv}%
-\xint_tmp_def {v}%
-\def\xint_tmp_def #1%
-{%
- \expandafter\xint_tmp_do_defs
- \csname XINT_expr_op_-#1\expandafter\endcsname
- \csname XINT_expr_until_-#1\expandafter\endcsname
- \csname XINT_expr_checkifprefix_#1\expandafter\endcsname
- \csname xint_c_#1\endcsname
-}%
-\def\xint_tmp_do_defs #1#2#3#4%
-{%
- \def #1% \XINT_expr_op_-ii,iii,iv,v
- {%
- \expandafter #2\romannumeral-`0\expandafter
- #3\romannumeral-`0\XINT_expr_getnext
- }%
- \def #2##1##2##3% \XINT_expr_until_-ii,iii,iv,v
- {%
- \ifnum ##1>#4%
- \xint_afterfi {\expandafter #2\romannumeral-`0##2##3}%
- \else
- \xint_afterfi {\expandafter ##1\expandafter ##2%
- \csname .\xintOpp{\XINT_expr_string ##3}\endcsname }%
- \fi
- }%
-}%
-\xint_tmp_def {ii}%
-\xint_tmp_def {iii}%
-\xint_tmp_def {iv}%
-\xint_tmp_def {v}%
-\def\XINT_expr_getop #1%
-{%
- \expandafter\XINT_expr_getop_a\expandafter #1%
- \romannumeral-`0\romannumeral-`0%
-}%
-\def\XINT_expr_getop_a #1#2%
-{%
- \ifcat #2\relax
- \ifx #2\relax
- \expandafter\expandafter\expandafter
- \XINT_expr_foundendofexpr
- \else
- \XINT_expr_unexpectedtoken
- \expandafter\expandafter\expandafter
- \XINT_expr_getop
- \fi
- \else
- \expandafter\XINT_expr_op_found\expandafter #2%
- \fi
- #1%
+ \expandafter\XINT_expr_until_end_a \romannumeral-`0\XINT_expr_getnext
}%
-\def\XINT_expr_foundendofexpr {\xint_c_ \XINT_expr_endofexpr }%
-\def\XINT_expr_op_found #1%
-{%
- \ifcsname XINT_expr_precedence_\string #1\endcsname
- \expandafter\xint_afterfi\expandafter
- {\csname XINT_expr_precedence_\string #1\expandafter\endcsname
- \csname XINT_expr_op_\string #1\endcsname }%
- \else
- \XINT_expr_unexpectedtoken
- \expandafter\XINT_expr_getop
- \fi
-}%
-\expandafter\let\csname XINT_expr_precedence_)\endcsname \xint_c_i
-\expandafter\let\csname XINT_expr_op_)\endcsname\XINT_expr_getop
-\def\xint_tmp_def
-{%
- \expandafter\xint_tmp_do_defs
- \csname XINT_expr_precedence_!\expandafter\endcsname
- \csname XINT_expr_op_!\endcsname
-}%
-\def\xint_tmp_do_defs #1#2%
+\def\xinttheeval {\expandafter\xint_gobble_ii\romannumeral0\xinteval }%
+\def\xinttheexpr {\romannumeral-`0\xinttheeval }%
+\def\XINT_numexpr_post !\XINT_expr_usethe\XINT_expr_print%
+ { !\XINT_expr_usethe\XINT_numexpr_print }%
+\def\xintnumexpr {\romannumeral0\expandafter\XINT_numexpr_post
+ \romannumeral0\xinteval }%
+\def\xintthenumexpr {\romannumeral-`0\xintthe\xintnumexpr }%
+\def\xintfloatexpr {\romannumeral0\xintfloateval }%
+\def\xintfloateval
{%
- \def #1##1##2%
- {\ifx ##1#2%
- \expandafter\xint_firstoftwo
- \else\expandafter\xint_secondoftwo
- \fi{\expandafter\XINT_expr_getop}{\expandafter\XINT_flexpr_getop}%
- \csname .\xintFac{\XINT_expr_string ##2}/1[0]\endcsname }%
- \let#2\empty
+ \expandafter\XINT_flexpr_until_end_a \romannumeral-`0\XINT_expr_getnext
}%
-\xint_tmp_def
+\def\xintthefloatexpr {\romannumeral-`0\xintthe\xintfloatexpr }%
+\def\xintthe #1{\romannumeral-`0\expandafter\xint_gobble_ii\romannumeral-`0#1}%
\def\XINT_expr_getnext
{%
\expandafter\XINT_expr_getnext_checkforbraced_a
@@ -385,300 +241,648 @@
#2\dummy \XINT_expr_getnext_onetoken_wehope
\W\dummy \XINT_expr_getnext_gotbracedstuff
\krof
-}%
+}% doubly braced things are not acceptable, will cause errors.
\def\XINT_expr_getnext_emptybracepair #1{\XINT_expr_getnext }%
-\def\XINT_expr_getnext_gotbracedstuff #1\W\Z #2%
+\def\XINT_expr_getnext_gotbracedstuff #1\W\Z #2% {..} -> number/fraction
{%
\expandafter\XINT_expr_getop\csname .#2\endcsname
}%
-\def\XINT_expr_getnext_onetoken_wehope\Z #1%
+\def\XINT_expr_getnext_onetoken_wehope\Z #1% #1 isn't a control sequence!
{%
\xint_gob_til_! #1\XINT_expr_subexpr !%
\expandafter\XINT_expr_getnext_onetoken_fork\string #1%
-}%
-\def\XINT_expr_subexpr !#1!{\expandafter\XINT_expr_getop\xint_gobble_i }%
+}% after this #1 should be now a catcode 12 token.
+\def\XINT_expr_subexpr !#1!{\expandafter\XINT_expr_getop\xint_gobble_ii }%
\begingroup
-\lccode`*=`_
+\lccode`*=`#
\lowercase{\endgroup
\def\XINT_expr_sixwayfork #1(-.+*\dummy #2#3\krof {#2}%
\def\XINT_expr_getnext_onetoken_fork #1%
-{%
+{% The * is in truth catcode 12 #. For (clever!) use with \xintNewExpr.
\XINT_expr_sixwayfork
- #1-.+*\dummy \XINT_expr_oparen
+ #1-.+*\dummy {\xint_c_x ({}}% back to until to trigger oparen
(#1.+*\dummy -%
- (-#1+*\dummy {\XINT_expr_scannum_start\XINT_expr_scannum_decpart_b.}%
+ (-#1+*\dummy {\XINT_expr_scandec_II.}%
(-.#1*\dummy \XINT_expr_getnext%
- (-.+#1\dummy {\XINT_expr_scannum_start\XINT_expr_scannum_decpart_b*}%
- (-.+*\dummy {\XINT_expr_scannum_check #1}%
+ (-.+#1\dummy {\XINT_expr_scandec_II}%
+ (-.+*\dummy {\XINT_expr_scan_dec_or_func #1}%
\krof
}}%
-\def\XINT_expr_scannum_check #1%
+\def\XINT_expr_scan_dec_or_func #1% this #1 of catcode 12
{%
\ifnum \xint_c_ix<1#1
- \expandafter\XINT_expr_scannum_start
+ \expandafter\XINT_expr_scandec_I
+ \else % We assume we are dealing with a function name!!
+ \expandafter\XINT_expr_scanfunc
+ \fi #1%
+}%
+\def\XINT_expr_scanfunc
+{%
+ \expandafter\XINT_expr_func\romannumeral-`0\XINT_expr_scanfunc_c
+}%
+\def\XINT_expr_scanfunc_c #1%
+{%
+ \expandafter #1\romannumeral-`0\expandafter
+ \XINT_expr_scanfunc_a\romannumeral-`0\romannumeral-`0%
+}%
+\def\XINT_expr_scanfunc_a #1% please no braced things here!
+{%
+ \ifcat #1\relax % missing opening parenthesis, probably
+ \expandafter\XINT_expr_scanfunc_panic
\else
- \xint_afterfi{\XINT_expr_unexpectedtoken
- \expandafter\XINT_expr_getnext\xint_gobble_ii}%
- \fi \XINT_expr_scannum_intpart_b #1%
+ \xint_afterfi{\expandafter\XINT_expr_scanfunc_b \string #1}%
+ \fi
+}%
+\def\XINT_expr_scanfunc_b #1%
+{%
+ \if #1(\else\expandafter \XINT_expr_scanfunc_c \fi #1%
+}%
+\def\XINT_expr_scanfunc_panic {\xintError:bigtroubleahead(0\relax }%
+\def\XINT_expr_func #1(% common to expr and flexpr
+{%
+ \xint_c_x @{#1}%
}%
-\def\XINT_expr_scannum_stopscan {!}% ! catcode 11
-\def\XINT_expr_gathernum #1!% ! with catcode 11
+\def\XINT_expr_scandec_I
{%
- \expandafter\space\csname .#1\endcsname
+ \expandafter\XINT_expr_getop\romannumeral-`0\expandafter
+ \XINT_expr_lock\romannumeral-`0\XINT_expr_scanintpart_b
}%
-\def\XINT_expr_scannum_start #1%
+\def\XINT_expr_scandec_II
{%
- \expandafter\XINT_expr_getop
- \romannumeral-`0\expandafter\XINT_expr_gathernum
- \romannumeral-`0#1%
+ \expandafter\XINT_expr_getop\romannumeral-`0\expandafter
+ \XINT_expr_lock\romannumeral-`0\XINT_expr_scanfracpart_b
}%
-\def\XINT_expr_scannum_intpart_a #1%
+\def\XINT_expr_scanintpart_a #1%
{%
\ifnum \xint_c_ix<1\string#1
- \expandafter\expandafter\expandafter
- \XINT_expr_scannum_intpart_b
+ \expandafter\expandafter\expandafter\XINT_expr_scanintpart_b
\expandafter\string
\else
\if #1.%
\expandafter\expandafter\expandafter
- \XINT_expr_scannum_transition
+ \XINT_expr_scandec_transition
\else
- \expandafter\expandafter\expandafter
- \XINT_expr_scannum_stopscan
+ \expandafter\expandafter\expandafter !% ! of catcode 11...
\fi
\fi
#1%
}%
-\def\XINT_expr_scannum_intpart_b #1%
+\def\XINT_expr_scanintpart_b #1%
{%
\expandafter #1\romannumeral-`0\expandafter
- \XINT_expr_scannum_intpart_a\romannumeral-`0\romannumeral-`0%
+ \XINT_expr_scanintpart_a\romannumeral-`0\romannumeral-`0%
}%
-\def\XINT_expr_scannum_transition #1%
+\def\XINT_expr_scandec_transition #1%
{%
\expandafter.\romannumeral-`0\expandafter
- \XINT_expr_scannum_decpart_a\romannumeral-`0\romannumeral-`0%
+ \XINT_expr_scanfracpart_a\romannumeral-`0\romannumeral-`0%
}%
-\def\XINT_expr_scannum_decpart_a #1%
+\def\XINT_expr_scanfracpart_a #1%
{%
\ifnum \xint_c_ix<1\string#1
- \expandafter\expandafter\expandafter
- \XINT_expr_scannum_decpart_b\expandafter\string
+ \expandafter\expandafter\expandafter\XINT_expr_scanfracpart_b
+ \expandafter\string
\else
- \expandafter \XINT_expr_scannum_stopscan
+ \expandafter !%
\fi
#1%
}%
-\def\XINT_expr_scannum_decpart_b #1%
+\def\XINT_expr_scanfracpart_b #1%
{%
\expandafter #1\romannumeral-`0\expandafter
- \XINT_expr_scannum_decpart_a\romannumeral-`0\romannumeral-`0%
+ \XINT_expr_scanfracpart_a\romannumeral-`0\romannumeral-`0%
}%
-\def\xintfloatexpr {\romannumeral0\xintfloateval }%
-\def\xintfloateval
+\def\XINT_expr_getop #1% this #1 is the current locked computed value
+{% full expansion of next token, first swallowing a possible space
+ \expandafter\XINT_expr_getop_a\expandafter #1%
+ \romannumeral-`0\romannumeral-`0%
+}%
+\def\XINT_expr_getop_a #1#2%
+{% if an un-expandable control sequence is found, must be the ending \relax
+ \ifcat #2\relax
+ \ifx #2\relax
+ \expandafter\expandafter\expandafter
+ \XINT_expr_foundend
+ \else
+ \XINT_expr_unexpectedtoken
+ \expandafter\expandafter\expandafter
+ \XINT_expr_getop
+ \fi
+ \else
+ \expandafter\XINT_expr_foundop\expandafter #2%
+ \fi
+ #1%
+}%
+\def\XINT_expr_foundend {\xint_c_ \relax }% \relax is a place holder here.
+\def\XINT_expr_foundop #1% then becomes <prec> <op> and is followed by <\.f>
+{% 1.09a: no control sequence \XINT_expr_op_#1, code common to expr/flexpr
+ \ifcsname XINT_expr_precedence_#1\endcsname
+ \expandafter\xint_afterfi\expandafter
+ {\csname XINT_expr_precedence_#1\endcsname #1}%
+ \else
+ \XINT_expr_unexpectedtoken
+ \expandafter\XINT_expr_getop
+ \fi
+}%
+\def\xint_tmp_do_defs #1#2#3#4#5%
{%
- \expandafter\XINT_expr_until_end\romannumeral-`0%
- \expandafter\XINT_flexpr_checkifprefix_ii\romannumeral-`0%
- \XINT_flexpr_getnext
+ \def#1##1%
+ {%
+ \xint_UDsignfork
+ ##1\dummy {\expandafter#1\romannumeral-`0#3}%
+ -\dummy {#2##1}%
+ \krof
+ }%
+ \def#2##1##2%
+ {%
+ \ifcase ##1\expandafter #4%
+ \or \xint_afterfi{%
+ \XINT_expr_extra_closing_paren
+ \expandafter #1\romannumeral-`0\XINT_expr_getop
+ }%
+ \else \xint_afterfi{%
+ \expandafter#1\romannumeral-`0\csname XINT_#5_op_##2\endcsname
+ }%
+ \fi
+ }%
}%
-\def\xintthefloatexpr {\romannumeral0\xintthefloateval }%
-\def\xintthefloateval
- {\expandafter\XINT_flexpr_the\romannumeral0\xintfloateval }%
-\def\XINT_flexpr_the #1#2#3{\xintfloat{\XINT_expr_string #3}}%
-\def\XINT_flexpr_oparen
+\expandafter\xint_tmp_do_defs
+ \csname XINT_expr_until_end_a\expandafter\endcsname
+ \csname XINT_expr_until_end_b\expandafter\endcsname
+ \csname XINT_expr_op_-vi\expandafter\endcsname
+ \csname XINT_expr_done\endcsname
+ {expr}%
+\expandafter\xint_tmp_do_defs
+ \csname XINT_flexpr_until_end_a\expandafter\endcsname
+ \csname XINT_flexpr_until_end_b\expandafter\endcsname
+ \csname XINT_flexpr_op_-vi\expandafter\endcsname
+ \csname XINT_flexpr_done\endcsname
+ {flexpr}%
+\def\XINT_expr_extra_closing_paren {\xintError:removed }%
+\def\xint_tmp_do_defs #1#2#3#4#5#6%
{%
- \expandafter\XINT_expr_until_cparen\romannumeral-`0%
- \expandafter\XINT_flexpr_checkifprefix_ii\romannumeral-`0%
- \XINT_flexpr_getnext
+ \def #1{\expandafter #3\romannumeral-`0\XINT_expr_getnext }%
+ \let #2#1%
+ \def #3##1{\xint_UDsignfork
+ ##1\dummy {\expandafter #3\romannumeral-`0#5}%
+ -\dummy {#4##1}%
+ \krof }%
+ \def #4##1##2%
+ {%
+ \ifcase ##1\expandafter \XINT_expr_missing_cparen
+ \or \expandafter \XINT_expr_getop
+ \else \xint_afterfi
+ {\expandafter #3\romannumeral-`0\csname XINT_#6_op_##2\endcsname }%
+ \fi
+ }%
}%
-\def\xint_tmp_def #1#2#3%
+\expandafter\xint_tmp_do_defs
+ \csname XINT_expr_op_(\expandafter\endcsname
+ \csname XINT_expr_oparen\expandafter\endcsname
+ \csname XINT_expr_until_)_a\expandafter\endcsname
+ \csname XINT_expr_until_)_b\expandafter\endcsname
+ \csname XINT_expr_op_-vi\endcsname
+ {expr}%
+\expandafter\xint_tmp_do_defs
+ \csname XINT_flexpr_op_(\expandafter\endcsname
+ \csname XINT_flexpr_oparen\expandafter\endcsname
+ \csname XINT_flexpr_until_)_a\expandafter\endcsname
+ \csname XINT_flexpr_until_)_b\expandafter\endcsname
+ \csname XINT_flexpr_op_-vi\endcsname
+ {flexpr}%
+\def\XINT_expr_missing_cparen {\xintError:inserted \xint_c_ \XINT_expr_done }%
+\expandafter\let\csname XINT_expr_precedence_)\endcsname \xint_c_i
+\expandafter\let\csname XINT_expr_op_)\endcsname\XINT_expr_getop
+\expandafter\let\csname XINT_flexpr_precedence_)\endcsname \xint_c_i
+\expandafter\let\csname XINT_flexpr_op_)\endcsname\XINT_expr_getop
+\def\xint_tmp_def #1#2#3#4#5#6%
{%
\expandafter\xint_tmp_do_defs
- \csname XINT_flexpr_op_#1\expandafter\endcsname
- \csname XINT_flexpr_until_#1\expandafter\endcsname
- \csname XINT_flexpr_checkifprefix_#2\expandafter\endcsname
- \csname XINT_expr_precedence_#1\expandafter\endcsname
- \csname xint_c_#2\expandafter\endcsname
- \csname XINTinFloat#3\endcsname
+ \csname XINT_#1_op_#3\expandafter\endcsname
+ \csname XINT_#1_until_#3_a\expandafter\endcsname
+ \csname XINT_#1_until_#3_b\expandafter\endcsname
+ \csname XINT_#1_op_-#5\expandafter\endcsname
+ \csname xint_c_#4\expandafter\endcsname
+ \csname #2#6\expandafter\endcsname
+ \csname XINT_expr_precedence_#3\endcsname {#1}%
+}%
+\def\xint_tmp_do_defs #1#2#3#4#5#6#7#8%
+{%
+ \def #1##1% \XINT_expr_op_<op>
+ {% keep value, get next number and operator, then do until
+ \expandafter #2\expandafter ##1%
+ \romannumeral-`0\expandafter\XINT_expr_getnext
+ }%
+ \def #2##1##2% \XINT_expr_until_<op>_a
+ {\xint_UDsignfork
+ ##2\dummy {\expandafter #2\expandafter ##1\romannumeral-`0#4}%
+ -\dummy {#3##1##2}%
+ \krof }%
+ \def #3##1##2##3##4% \XINT_expr_until_<op>_b
+ {% either execute next operation now, or first do next (possibly unary)
+ \ifnum ##2>#5%
+ \xint_afterfi {\expandafter #2\expandafter ##1\romannumeral-`0%
+ \csname XINT_#8_op_##3\endcsname {##4}}%
+ \else
+ \xint_afterfi
+ {\expandafter ##2\expandafter ##3%
+ \csname .#6{\XINT_expr_unlock ##1}{\XINT_expr_unlock ##4}\endcsname }%
+ \fi
+ }%
+ \let #7#5%
}%
+\def\xint_tmp_def_a #1{\xint_tmp_def {expr}{xint}#1}%
+\xintApplyInline {\xint_tmp_def_a }{%
+ {|{iii}{vi}{OR}}%
+ {&{iv}{vi}{AND}}%
+ {<{v}{vi}{Lt}}%
+ {>{v}{vi}{Gt}}%
+ {={v}{vi}{Eq}}%
+ {+{vi}{vi}{Add}}%
+ {-{vi}{vi}{Sub}}%
+ {*{vii}{vii}{Mul}}%
+ {/{vii}{vii}{Div}}%
+ {^{viii}{viii}{Pow}}%
+ {e{ix}{ix}{fE}}%
+ {E{ix}{ix}{fE}}%
+}%
+\def\xint_tmp_def_a #1{\xint_tmp_def {flexpr}{xint}#1}%
+\xintApplyInline {\xint_tmp_def_a }{%
+ {|{iii}{vi}{OR}}%
+ {&{iv}{vi}{AND}}%
+ {<{v}{vi}{Lt}}%
+ {>{v}{vi}{Gt}}%
+ {={v}{vi}{Eq}}%
+}%
+\def\xint_tmp_def_a #1{\xint_tmp_def {flexpr}{XINTinFloat}#1}%
+\xintApplyInline {\xint_tmp_def_a }{%
+ {+{vi}{vi}{Add}}%
+ {-{vi}{vi}{Sub}}%
+ {*{vii}{vii}{Mul}}%
+ {/{vii}{vii}{Div}}%
+ {^{viii}{viii}{Power}}%
+ {e{ix}{ix}{fE}}%
+ {E{ix}{ix}{fE}}%
+}%
+\let\xint_tmp_def_a\empty
\def\xint_tmp_do_defs #1#2#3#4#5#6%
{%
- \def #1##1% \XINT_flexpr_op_?
+ \def #1##1% \XINT_expr_op_,_a
{%
- \expandafter #2\expandafter ##1\romannumeral-`0\expandafter
- #3\romannumeral-`0\XINT_flexpr_getnext
+ \expandafter #2\expandafter ##1\romannumeral-`0\XINT_expr_getnext
}%
- \def #2##1##2##3##4% \XINT_flexpr_until_?
+ \def #2##1##2% \XINT_expr_until_,_a
+ {\xint_UDsignfork
+ ##2\dummy {\expandafter #2\expandafter ##1\romannumeral-`0#4}%
+ -\dummy {#3##1##2}%
+ \krof }%
+ \def #3##1##2##3##4% \XINT_expr_until_,_b
{%
- \ifnum ##2>#5%
- \xint_afterfi {\expandafter #2\expandafter ##1\romannumeral-`0##3##4}%
+ \ifnum ##2>\xint_c_ii
+ \xint_afterfi {\expandafter #2\expandafter ##1\romannumeral-`0%
+ \csname XINT_#6_op_##3\endcsname {##4}}%
\else
\xint_afterfi
{\expandafter ##2\expandafter ##3%
- \csname .#6{\XINT_expr_string ##1}%
- {\XINT_expr_string ##4}\endcsname }%
+ \csname .\XINT_expr_unlock ##1,\XINT_expr_unlock ##4\endcsname }%
\fi
}%
+ \let #5\xint_c_ii
}%
-\xint_tmp_def +{ii}{Add}%
-\xint_tmp_def -{ii}{Sub}%
-\xint_tmp_def *{iii}{Mul}%
-\xint_tmp_def /{iii}{Div}%
-\xint_tmp_def ^{iv}{Power}%
-\xint_tmp_def e{v}{fE}%
-\xint_tmp_def E{v}{fE}%
-\def\xint_tmp_def #1%
+\expandafter\xint_tmp_do_defs
+ \csname XINT_expr_op_,\expandafter\endcsname
+ \csname XINT_expr_until_,_a\expandafter\endcsname
+ \csname XINT_expr_until_,_b\expandafter\endcsname
+ \csname XINT_expr_op_-vi\expandafter\endcsname
+ \csname XINT_expr_precedence_,\endcsname {expr}%
+\expandafter\xint_tmp_do_defs
+ \csname XINT_flexpr_op_,\expandafter\endcsname
+ \csname XINT_flexpr_until_,_a\expandafter\endcsname
+ \csname XINT_flexpr_until_,_b\expandafter\endcsname
+ \csname XINT_flexpr_op_-vi\expandafter\endcsname
+ \csname XINT_expr_precedence_,\endcsname {flexpr}%
+\def \XINT_expr_precedence_? #1#2#3#4%
{%
- \expandafter\xint_tmp_do_defs
- \csname XINT_flexpr_checkifprefix_#1\expandafter\endcsname
- \csname XINT_flexpr_op_-#1\endcsname
+ \xintifZero{\XINT_expr_unlock #2}%
+ {\XINT_expr_getnext #4}%
+ {\XINT_expr_getnext #3}%
}%
-\def\xint_tmp_do_defs #1#2%
+\def \XINT_expr_precedence_: #1#2#3#4#5%
{%
- \def #1##1%
- {\xint_UDsignfork
- ##1\dummy #2%
- -\dummy ##1%
- \krof }%
+ \xintifSgn {\XINT_expr_unlock #2}%
+ {\XINT_expr_getnext #3}%
+ {\XINT_expr_getnext #4}%
+ {\XINT_expr_getnext #5}%
}%
-\xint_tmp_def {ii}%
-\xint_tmp_def {iii}%
-\xint_tmp_def {iv}%
-\xint_tmp_def {v}%
-\def\xint_tmp_def #1%
+\def\xint_tmp_def #1#2%
{%
\expandafter\xint_tmp_do_defs
- \csname XINT_flexpr_op_-#1\expandafter\endcsname
- \csname XINT_expr_until_-#1\expandafter\endcsname
- \csname XINT_flexpr_checkifprefix_#1\expandafter\endcsname
- \csname xint_c_#1\endcsname
+ \csname XINT_#1_op_-#2\expandafter\endcsname
+ \csname XINT_#1_until_-#2_a\expandafter\endcsname
+ \csname XINT_#1_until_-#2_b\expandafter\endcsname
+ \csname xint_c_#2\endcsname {#1}%
}%
-\def\xint_tmp_do_defs #1#2#3#4%
+\def\xint_tmp_do_defs #1#2#3#4#5%
{%
- \def #1% \XINT_flexpr_op_-ii,iii,iv,v
- {%
- \expandafter #2\romannumeral-`0\expandafter
- #3\romannumeral-`0\XINT_flexpr_getnext
+ \def #1% \XINT_expr_op_-<level>
+ {% get next number+operator then switch to _until macro
+ \expandafter #2\romannumeral-`0\XINT_expr_getnext
+ }%
+ \def #2##1% \XINT_expr_until_-<l>_a
+ {\xint_UDsignfork
+ ##1\dummy {\expandafter #2\romannumeral-`0#1}%
+ -\dummy {#3##1}%
+ \krof }%
+ \def #3##1##2##3% \XINT_expr_until_-<l>_b
+ {% _until tests precedence level with next op, executes now or postpones
+ \ifnum ##1>#4%
+ \xint_afterfi {\expandafter #2\romannumeral-`0%
+ \csname XINT_#5_op_##2\endcsname {##3}}%
+ \else
+ \xint_afterfi {\expandafter ##1\expandafter ##2%
+ \csname .\xintOpp{\XINT_expr_unlock ##3}\endcsname }%
+ \fi
}%
}%
-\xint_tmp_def {ii}%
-\xint_tmp_def {iii}%
-\xint_tmp_def {iv}%
-\xint_tmp_def {v}%
+\xintApplyInline{\xint_tmp_def {expr}}{{vi}{vii}{viii}{ix}}%
+\xintApplyInline{\xint_tmp_def {flexpr}}{{vi}{vii}{viii}{ix}}%
+\expandafter\def\csname XINT_expr_precedence_!\endcsname #1#2%
+ {\expandafter\XINT_expr_getop
+ \csname .\xintFac{\XINT_expr_unlock #2}[0]\endcsname }%
\let\xint_tmp_def\empty
\let\xint_tmp_do_defs\empty
-\def\XINT_flexpr_getop #1%
+\def\XINT_expr_op_@ #1%
{%
- \expandafter\XINT_flexpr_getop_a\expandafter #1%
- \romannumeral-`0\romannumeral-`0%
+ \ifcsname XINT_expr_func_#1\endcsname
+ \xint_afterfi{%
+ \expandafter\expandafter\csname XINT_expr_func_#1\endcsname
+ }%
+ \else \xintError:unknownfunction
+ \xint_afterfi{\expandafter\XINT_expr_func_unknown}%
+ \fi
+ \romannumeral-`0\XINT_expr_oparen
}%
-\def\XINT_flexpr_getop_a #1#2%
+\def\XINT_flexpr_op_@ #1%
{%
- \ifcat #2\relax
- \ifx #2\relax
- \expandafter\expandafter\expandafter
- \XINT_expr_foundendofexpr
- \else
- \XINT_expr_unexpectedtoken
- \expandafter\expandafter\expandafter
- \XINT_flexpr_getop
- \fi
- \else
- \expandafter\XINT_flexpr_op_found\expandafter #2%
+ \ifcsname XINT_flexpr_func_#1\endcsname
+ \xint_afterfi{%
+ \expandafter\expandafter\csname XINT_flexpr_func_#1\endcsname
+ }%
+ \else \xintError:unknownfunction
+ \xint_afterfi{\expandafter\XINT_expr_func_unknown}%
\fi
- #1%
+ \romannumeral-`0\XINT_flexpr_oparen
}%
-\def\XINT_flexpr_op_found #1%
+\def\XINT_expr_func_unknown #1#2#3%
{%
- \ifcsname XINT_expr_precedence_\string #1\endcsname
- \expandafter\xint_afterfi\expandafter
- {\csname XINT_expr_precedence_\string #1\expandafter\endcsname
- \csname XINT_flexpr_op_\string #1\endcsname }%
- \else
- \XINT_expr_unexpectedtoken
- \expandafter\XINT_flexpr_getop
- \fi
+ \expandafter #1\expandafter #2\csname .0[0]\endcsname
}%
-\expandafter\let\csname XINT_flexpr_op_)\endcsname\XINT_flexpr_getop
-\def\XINT_flexpr_getnext
+\def\XINT_expr_func_reduce #1#2#3%
{%
- \expandafter\XINT_flexpr_getnext_checkforbraced_a
- \romannumeral-`0\romannumeral-`0%
+ \expandafter #1\expandafter #2\csname
+ .\xintIrr {\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_checkforbraced_a #1%
+\let\XINT_flexpr_func_reduce\XINT_expr_func_reduce
+\def\XINT_expr_func_sqr #1#2#3%
{%
- \XINT_flexpr_getnext_checkforbraced_b #1\W\Z {#1}%
+ \expandafter #1\expandafter #2\csname
+ .\xintSqr {\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_checkforbraced_b #1#2%
+\def\XINT_flexpr_func_sqr #1#2#3%
{%
- \xint_UDwfork
- #1\dummy \XINT_flexpr_getnext_emptybracepair
- #2\dummy \XINT_flexpr_getnext_onetoken_perhaps
- \W\dummy \XINT_flexpr_getnext_gotbracedstuff
- \krof
+ \expandafter #1\expandafter #2\csname
+ .\XINTinFloatMul {\XINT_expr_unlock #3}{\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_onetoken_perhaps\Z #1%
+\def\XINT_expr_func_abs #1#2#3%
{%
- \expandafter\XINT_flexpr_getnext_checkforbraced_c\expandafter
- {\romannumeral-`0#1}%
+ \expandafter #1\expandafter #2\csname
+ .\xintAbs {\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_checkforbraced_c #1%
+\let\XINT_flexpr_func_abs\XINT_expr_func_abs
+\def\XINT_expr_func_sgn #1#2#3%
{%
- \XINT_flexpr_getnext_checkforbraced_d #1\W\Z {#1}%
+ \expandafter #1\expandafter #2\csname
+ .\xintSgn {\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_checkforbraced_d #1#2%
+\let\XINT_flexpr_func_sgn\XINT_expr_func_sgn
+\def\XINT_expr_func_floor #1#2#3%
{%
- \xint_UDwfork
- #1\dummy \XINT_flexpr_getnext_emptybracepair
- #2\dummy \XINT_flexpr_getnext_onetoken_wehope
- \W\dummy \XINT_flexpr_getnext_gotbracedstuff
- \krof
+ \expandafter #1\expandafter #2\csname
+ .\xintFloor {\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_emptybracepair #1{\XINT_flexpr_getnext }%
-\def\XINT_flexpr_getnext_gotbracedstuff #1\W\Z #2%
+\let\XINT_flexpr_func_floor\XINT_expr_func_floor
+\def\XINT_expr_func_ceil #1#2#3%
{%
- \expandafter\XINT_flexpr_getop\csname .#2\endcsname
+ \expandafter #1\expandafter #2\csname
+ .\xintCeil {\XINT_expr_unlock #3}\endcsname
}%
-\def\XINT_flexpr_getnext_onetoken_wehope\Z #1%
+\let\XINT_flexpr_func_ceil\XINT_expr_func_ceil
+\def\XINT_expr_twoargs #1,#2,{{#1}{#2}}%
+\def\XINT_expr_func_quo #1#2#3%
{%
- \xint_gob_til_! #1\XINT_flexpr_subexpr !%
- \expandafter\XINT_flexpr_getnext_onetoken_fork\string #1%
+ \expandafter #1\expandafter #2\csname .%
+ \expandafter\expandafter\expandafter\xintQuo
+ \expandafter\XINT_expr_twoargs
+ \romannumeral-`0\XINT_expr_unlock #3,\endcsname
}%
-\def\XINT_flexpr_subexpr !#1!{\expandafter\XINT_flexpr_getop\xint_gobble_i }%
-\begingroup
-\lccode`*=`_
-\lowercase{\endgroup
-\def\XINT_flexpr_getnext_onetoken_fork #1%
+\let\XINT_flexpr_func_quo\XINT_expr_func_quo
+\def\XINT_expr_func_rem #1#2#3%
{%
- \XINT_expr_sixwayfork
- #1-.+*\dummy \XINT_flexpr_oparen
- (#1.+*\dummy -%
- (-#1+*\dummy {\XINT_flexpr_scannum_start\XINT_expr_scannum_decpart_b.}%
- (-.#1*\dummy \XINT_flexpr_getnext%
- (-.+#1\dummy {\XINT_flexpr_scannum_start\XINT_expr_scannum_decpart_b*}%
- (-.+*\dummy {\XINT_flexpr_scannum_check #1}%
- \krof
-}}%
-\def\XINT_flexpr_scannum_check #1%
+ \expandafter #1\expandafter #2\csname .%
+ \expandafter\expandafter\expandafter\xintRem
+ \expandafter\XINT_expr_twoargs
+ \romannumeral-`0\XINT_expr_unlock #3,\endcsname
+}%
+\let\XINT_flexpr_func_rem\XINT_expr_func_rem
+\def\XINT_expr_oneortwo #1#2#3,#4,#5.%
{%
- \ifnum \xint_c_ix<1#1
- \expandafter\XINT_flexpr_scannum_start
- \else
- \xint_afterfi
- {\XINT_expr_unexpectedtoken
- \expandafter\XINT_flexpr_getnext\xint_gobble_ii}%
- \fi \XINT_expr_scannum_intpart_b #1%
+ \if\relax#5\relax\expandafter\xint_firstoftwo\else
+ \expandafter\xint_secondoftwo\fi
+ {#1{0}{#3}}{#2{\xintNum {#4}}{#3}}%
+}%
+\def\XINT_expr_func_round #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname .%
+ \expandafter\XINT_expr_oneortwo
+ \expandafter\xintiRound\expandafter\xintRound
+ \romannumeral-`0\XINT_expr_unlock #3,,.\endcsname
+}%
+\let\XINT_flexpr_func_round\XINT_expr_func_round
+\def\XINT_expr_func_trunc #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname .%
+ \expandafter\XINT_expr_oneortwo
+ \expandafter\xintiTrunc\expandafter\xintTrunc
+ \romannumeral-`0\XINT_expr_unlock #3,,.\endcsname
+}%
+\let\XINT_flexpr_func_trunc\XINT_expr_func_trunc
+\def\XINT_expr_argandopt #1,#2,#3.%
+{%
+ \if\relax#3\relax\expandafter\xint_firstoftwo\else
+ \expandafter\xint_secondoftwo\fi
+ {[\XINTdigits]{#1}}{[\xintNum {#2}]{#1}}%
+}%
+\def\XINT_expr_func_float #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname .%
+ \expandafter\XINTinFloat
+ \romannumeral-`0\expandafter\XINT_expr_argandopt
+ \romannumeral-`0\XINT_expr_unlock #3,,.\endcsname
}%
-\def\XINT_flexpr_scannum_start #1%
+\let\XINT_flexpr_func_float\XINT_expr_func_float
+\def\XINT_expr_func_sqrt #1#2#3%
{%
- \expandafter\XINT_flexpr_getop
- \romannumeral-`0\expandafter\XINT_expr_gathernum
- \romannumeral-`0#1%
+ \expandafter #1\expandafter #2\csname .%
+ \expandafter\XINTinFloatSqrt
+ \romannumeral-`0\expandafter\XINT_expr_argandopt
+ \romannumeral-`0\XINT_expr_unlock #3,,.\endcsname
+}%
+\let\XINT_flexpr_func_sqrt\XINT_expr_func_sqrt
+\def\XINT_expr_func_gcd #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintGCDof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_gcd\XINT_expr_func_gcd
+\def\XINT_expr_func_lcm #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintLCMof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_lcm\XINT_expr_func_lcm
+\def\XINT_expr_func_max #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintMaxof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_flexpr_func_max #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintFloatMaxof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_expr_func_min #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintMinof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_flexpr_func_min #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintFloatMinof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_expr_func_sum #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintSum:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_flexpr_func_sum #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintFloatSum:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_expr_func_prd #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintPrd:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\def\XINT_flexpr_func_prd #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintFloatPrd:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_expr_func_add\XINT_expr_func_sum
+\let\XINT_expr_func_mul\XINT_expr_func_prd
+\let\XINT_flexpr_func_add\XINT_flexpr_func_sum
+\let\XINT_flexpr_func_mul\XINT_flexpr_func_prd
+\def\XINT_expr_func_? #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintIsNotZero {\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_? \XINT_expr_func_?
+\def\XINT_expr_func_! #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintIsZero {\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_! \XINT_expr_func_!
+\def\XINT_expr_func_not #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintIsZero {\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_not \XINT_expr_func_not
+\def\XINT_expr_func_all #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintANDof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_all\XINT_expr_func_all
+\def\XINT_expr_func_any #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintORof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_any\XINT_expr_func_any
+\def\XINT_expr_func_xor #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\xintXORof:csv{\XINT_expr_unlock #3}\endcsname
+}%
+\let\XINT_flexpr_func_xor\XINT_expr_func_xor
+\def\xintifNotZero:: #1,#2,#3,{\xintifNotZero{#1}{#2}{#3}}%
+\def\XINT_expr_func_if #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\expandafter\xintifNotZero::
+ \romannumeral-`0\XINT_expr_unlock #3,\endcsname
+}%
+\let\XINT_flexpr_func_if\XINT_expr_func_if
+\def\xintifSgn:: #1,#2,#3,#4,{\xintifSgn{#1}{#2}{#3}{#4}}%
+\def\XINT_expr_func_ifsgn #1#2#3%
+{%
+ \expandafter #1\expandafter #2\csname
+ .\expandafter\xintifSgn::
+ \romannumeral-`0\XINT_expr_unlock #3,\endcsname
+}%
+\let\XINT_flexpr_func_ifsgn\XINT_expr_func_ifsgn
+\def\XINT_newexpr_print #1{\ifnum\xintNthElt{0}{#1}>1
+ \expandafter\xint_firstoftwo
+ \else
+ \expandafter\xint_secondoftwo
+ \fi
+ {_xintListWithSep,{#1}}{\xint_firstofone#1}}%
+\def\XINT_expr_tmp #1%
+ {\expandafter\def\csname xint#1\endcsname {_xint#1}}%
+\expandafter\def\expandafter\XINT_expr_protect\expandafter
+{%
+ \romannumeral0%
+ \xintapplyunbraced\XINT_expr_tmp{\xintCSVtoList{%
+ Floor,Ceil,iRound,Round,iTrunc,Trunc,%
+ Lt,Gt,Eq,AND,OR,%
+ IsNotZero,IsZero,%
+ ifNotZero,ifSgn,%
+ Irr,Num,Abs,Sgn,Opp,Quo,Rem,%
+ Add,Sub,Mul,Sqr,Div,Pow,Fac,fE}}%
+ \def\xintGCDof:csv ##1{_xintGCDof {\xintCSVtoList {##1}}}%
+ \def\xintLCMof:csv ##1{_xintLCMof {\xintCSVtoList {##1}}}%
+ \def\xintMaxof:csv ##1{_xintMaxof {\xintCSVtoList {##1}}}%
+ \def\xintMinof:csv ##1{_xintMinof {\xintCSVtoList {##1}}}%
+ \def\xintSum:csv ##1{_xintSum {\xintCSVtoList {##1}}}%
+ \def\xintPrd:csv ##1{_xintPrd {\xintCSVtoList {##1}}}%
+ \def\xintANDof:csv ##1{_xintANDof {\xintCSVtoList {##1}}}%
+ \def\xintORof:csv ##1{_xintORof {\xintCSVtoList {##1}}}%
+ \def\xintXORof:csv ##1{_xintXORof {\xintCSVtoList {##1}}}%
+ \def\XINTinFloat {_XINTinFloat}%
+ \def\XINTinFloatSqrt {_XINTinFloatSqrt}%
+ \def\XINTdigits {_XINTdigits}%
+ \def\XINT_expr_print ##1{\expandafter\XINT_newexpr_print\expandafter
+ {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}%
}%
\catcode`* 13
-\def\xintNewExpr #1[#2]#3%
+\def\xintNewExpr #1[#2]%
{%
- \begingroup
+ \begingroup
\ifcase #2\relax
\toks0 {\xdef #1}%
\or \toks0 {\xdef #1##1}%
@@ -690,37 +894,72 @@
\or \toks0 {\xdef #1##1##2##3##4##5##6##7}%
\or \toks0 {\xdef #1##1##2##3##4##5##6##7##8}%
\or \toks0 {\xdef #1##1##2##3##4##5##6##7##8##9}%
- \else
- \immediate\write-1{Package xintexpr Error! illegal number of macro
- parameters.}%
\fi
- \def\xintAdd {:xintAdd}%
- \def\xintSub {:xintSub}%
- \def\xintMul {:xintMul}%
- \def\xintDiv {:xintDiv}%
- \def\xintPow {:xintPow}%
- \def\xintFac {:xintFac}%
- \def\xintOpp {:xintOpp}%
- \def\xintfE {:xintfE}%
- \def\xintraw { :romannumeral0:xintraw}%
- \def\XINT_expr_the ##1##2##3%
- {\expandafter\xintraw
- \expandafter{\romannumeral-`0\XINT_expr_string ##3}}%
- \lccode`\*=`: \lowercase {\def*}{!noexpand!}%
- \catcode`: 13
- \endlinechar -1
+ \xintexprSafeCatcodes
+ \XINT_NewExpr
+}%
+\def\XINT_NewExpr #1%
+{%
+ \def\xintTmp ##1##2##3##4##5##6##7##8##9{#1}%
+ \XINT_expr_protect
+ \lccode`\*=`_ \lowercase {\def*}{!noexpand!}%
+ \catcode`_ 13 \catcode`: 11 \endlinechar -1
\everyeof {\noexpand }%
- \edef\xintNewExprtmp
+ \edef\XINTtmp ##1##2##3##4##5##6##7##8##9%
{\scantokens
- \expandafter{\romannumeral0\xinttheeval #3\relax}}%
- \lccode`\*=`_ \lowercase {\def*}{####}%
- \catcode`_ 13 \catcode`! 0 \catcode`: 11
- \the\toks0 {\scantokens\expandafter{\xintNewExprtmp }}%
+ \expandafter{\romannumeral-`0\xinttheexpr
+ \xintTmp {####1}{####2}{####3}%
+ {####4}{####5}{####6}%
+ {####7}{####8}{####9}%
+ \relax}}%
+ \lccode`\*=`\$ \lowercase {\def*}{####}%
+ \catcode`\$ 13 \catcode`! 0 \catcode`_ 11 %
+ \the\toks0
+ {\scantokens\expandafter{\expandafter
+ \XINT_newexpr_stripprefix\meaning\XINTtmp}}%
\endgroup
}%
-\def\xintNewFloatExpr #1[#2]#3%
+\def\XINT_newflexpr_print #1{\ifnum\xintNthElt{0}{#1}>1
+ \expandafter\xint_firstoftwo
+ \else
+ \expandafter\xint_secondoftwo
+ \fi
+ {_xintListWithSep,{\xintApply{_xintFloat}{#1}}}
+ {_xintFloat#1}}%
+\expandafter\def\expandafter\XINT_flexpr_protect\expandafter
{%
- \begingroup
+ \romannumeral0%
+ \xintapplyunbraced\XINT_expr_tmp{\xintCSVtoList{%
+ Floor,Ceil,iRound,Round,iTrunc,Trunc,%
+ Lt,Gt,Eq,AND,OR,%
+ IsNotZero,IsZero,%
+ ifNotZero,ifSgn,%
+ Irr,Num,Abs,Sgn,Opp,Quo,Rem,Fac}}%
+ \def\xintGCDof:csv ##1{_xintGCDof {\xintCSVtoList {##1}}}%
+ \def\xintLCMof:csv ##1{_xintLCMof {\xintCSVtoList {##1}}}%
+ \def\xintFloatMaxof:csv ##1{_xintFloatMaxof {\xintCSVtoList {##1}}}%
+ \def\xintFloatMinof:csv ##1{_xintFloatMinof {\xintCSVtoList {##1}}}%
+ \def\xintFloatSum:csv ##1{_xintFloatSum {\xintCSVtoList {##1}}}%
+ \def\xintFloatPrd:csv ##1{_xintFloatPrd {\xintCSVtoList {##1}}}%
+ \def\xintANDof:csv ##1{_xintANDof {\xintCSVtoList {##1}}}%
+ \def\xintORof:csv ##1{_xintORof {\xintCSVtoList {##1}}}%
+ \def\xintXORof:csv ##1{_xintXORof {\xintCSVtoList {##1}}}%
+ \def\XINTinFloat {_XINTinFloat}%
+ \def\XINTinFloatSqrt {_XINTinFloatSqrt}%
+ \def\XINTinFloatAdd {_XINTinFloatAdd}%
+ \def\XINTinFloatSub {_XINTinFloatSub}%
+ \def\XINTinFloatMul {_XINTinFloatMul}%
+ \def\XINTinFloatDiv {_XINTinFloatDiv}%
+ \def\XINTinFloatPower {_XINTinFloatPower}%
+ \def\XINTinFloatfE {_XINTinFloatfE}%
+ \def\XINTdigits {_XINTdigits}%
+ \def\XINT_flexpr_print ##1{\expandafter\XINT_newflexpr_print\expandafter
+ {\romannumeral0\xintcsvtolist{\XINT_expr_unlock ##1}}}%
+}%
+\let\XINT_expr_tmp\empty
+\def\xintNewFloatExpr #1[#2]%
+{%
+ \begingroup
\ifcase #2\relax
\toks0 {\xdef #1}%
\or \toks0 {\xdef #1##1}%
@@ -732,34 +971,77 @@
\or \toks0 {\xdef #1##1##2##3##4##5##6##7}%
\or \toks0 {\xdef #1##1##2##3##4##5##6##7##8}%
\or \toks0 {\xdef #1##1##2##3##4##5##6##7##8##9}%
- \else
- \immediate\write-1{Package xintexpr Error! illegal number of macro
- parameters.}%
\fi
- \def\XINTinFloatAdd {:XINTinFloatAdd}%
- \def\XINTinFloatSub {:XINTinFloatSub}%
- \def\XINTinFloatMul {:XINTinFloatMul}%
- \def\XINTinFloatDiv {:XINTinFloatDiv}%
- \def\XINTinFloatPower {:XINTinFloatPower}%
- \def\xintFac {:xintFac}%
- \def\xintOpp {:xintOpp}%
- \def\XINTinFloatfE {:XINTinFloatfE}%
- \def\xintfloat { :romannumeral0:xintfloat}%
- \def\XINT_flexpr_the ##1##2##3%
- {\expandafter\xintfloat
- \expandafter{\romannumeral-`0\XINT_expr_string ##3}}%
- \lccode`\*=`: \lowercase {\def*}{!noexpand!}%
- \catcode`: 13
- \endlinechar -1
+ \xintexprSafeCatcodes
+ \XINT_NewFloatExpr
+}%
+\def\XINT_NewFloatExpr #1%
+{%
+ \def\xintTmp ##1##2##3##4##5##6##7##8##9{#1}%
+ \XINT_flexpr_protect
+ \lccode`\*=`_ \lowercase {\def*}{!noexpand!}%
+ \catcode`_ 13 \catcode`: 11 \endlinechar -1 %
\everyeof {\noexpand }%
- \edef\xintNewExprtmp
+ \edef\XINTtmp ##1##2##3##4##5##6##7##8##9%
{\scantokens
- \expandafter{\romannumeral0\xintthefloateval #3\relax}}%
- \lccode`\*=`_ \lowercase {\def*}{####}%
- \catcode`_ 13 \catcode`! 0 \catcode`: 11
- \the\toks0 {\scantokens\expandafter{\xintNewExprtmp }}%
+ \expandafter{\romannumeral-`0\xintthefloatexpr
+ \xintTmp {####1}{####2}{####3}%
+ {####4}{####5}{####6}%
+ {####7}{####8}{####9}%
+ \relax}}%
+ \lccode`\*=`\$ \lowercase {\def*}{####}%
+ \catcode`\$ 13 \catcode`! 0 \catcode`_ 11 %
+ \the\toks0
+ {\scantokens\expandafter
+ {\expandafter\XINT_newexpr_stripprefix\meaning\XINTtmp}}%
\endgroup
}%
+\let\xintexprRestoreCatcodes\relax
+\def\xintexprSafeCatcodes
+{% for end user.
+ \edef\xintexprRestoreCatcodes {%
+ \catcode63=\the\catcode63 % ?
+ \catcode124=\the\catcode124 % |
+ \catcode38=\the\catcode38 % &
+ \catcode33=\the\catcode33 % !
+ \catcode93=\the\catcode93 % ]
+ \catcode91=\the\catcode91 % [
+ \catcode94=\the\catcode94 % ^
+ \catcode95=\the\catcode95 % _
+ \catcode47=\the\catcode47 % /
+ \catcode41=\the\catcode41 % )
+ \catcode40=\the\catcode40 % (
+ \catcode42=\the\catcode42 % *
+ \catcode43=\the\catcode43 % +
+ \catcode62=\the\catcode62 % >
+ \catcode60=\the\catcode60 % <
+ \catcode58=\the\catcode58 % :
+ \catcode46=\the\catcode46 % .
+ \catcode45=\the\catcode45 % -
+ \catcode44=\the\catcode44 % ,
+ \catcode61=\the\catcode61\relax % =
+ }% this is just for some standard situation with a few made active by Babel
+ \catcode63=12 % ?
+ \catcode124=12 % |
+ \catcode38=4 % &
+ \catcode33=12 % !
+ \catcode93=12 % ]
+ \catcode91=12 % [
+ \catcode94=7 % ^
+ \catcode95=8 % _
+ \catcode47=12 % /
+ \catcode41=12 % )
+ \catcode40=12 % (
+ \catcode42=12 % *
+ \catcode43=12 % +
+ \catcode62=12 % >
+ \catcode60=12 % <
+ \catcode58=12 % :
+ \catcode46=12 % .
+ \catcode45=12 % -
+ \catcode44=12 % ,
+ \catcode61=12 % =
+}%
\XINT_expr_restorecatcodes_endinput%
\endinput
%%