[latex3-commits] [l3svn] r7416 - For negative bases, only allow integer powers (see #385)

noreply at latex-project.org noreply at latex-project.org
Thu Aug 3 13:52:23 CEST 2017


Author: bruno
Date: 2017-08-03 13:52:22 +0200 (Thu, 03 Aug 2017)
New Revision: 7416

Modified:
   trunk/l3kernel/l3fp-aux.dtx
   trunk/l3kernel/l3fp-expo.dtx
   trunk/l3kernel/testfiles/m3fp-expo001.lvt
   trunk/l3kernel/testfiles/m3fp-expo001.tlg
Log:
For negative bases, only allow integer powers (see #385)

Not marking the issue as fixed since I still need to implement some
root(x,n) function.


Modified: trunk/l3kernel/l3fp-aux.dtx
===================================================================
--- trunk/l3kernel/l3fp-aux.dtx	2017-08-03 11:27:46 UTC (rev 7415)
+++ trunk/l3kernel/l3fp-aux.dtx	2017-08-03 11:52:22 UTC (rev 7416)
@@ -703,8 +703,9 @@
 %   \[
 %   \left(
 %     \sum_{i=1}^{4} \meta{X_i} \cdot 10^{-4i} \cdot 10^{-\meta{shift}}
-%     - \meta{X'_1} \cdot 10^{-8} + \meta{X'_2} \cdot 10^{-16}
 %   \right)
+%   - \bigl( \meta{X'_1} \cdot 10^{-8} + \meta{X'_2} \cdot 10^{-16} \bigr)
+%   = 0.\meta{extra-digits} \cdot 10^{-16}
 %   \in [0,10^{-16}).
 %   \]
 %   To round properly later, we need to remember some information

Modified: trunk/l3kernel/l3fp-expo.dtx
===================================================================
--- trunk/l3kernel/l3fp-expo.dtx	2017-08-03 11:27:46 UTC (rev 7415)
+++ trunk/l3kernel/l3fp-expo.dtx	2017-08-03 11:52:22 UTC (rev 7416)
@@ -868,24 +868,22 @@
 % Raising a number $a$ to a power $b$ leads to many distinct situations.
 % \begin{center}\def\abs#1{\lvert #1\rvert}
 %   \begin{tabular}{>{$}c<{$}|*8{>{$}l<{$}}}
-%     a^b          &-\infty &(-\infty,-0)  &-p/5^k              &\pm 0 &+p/5^k            &(0,\infty)      &+\infty &\nan \\ \hline
+%     a^b          &-\infty &(-\infty,-0)  &-\text{integer}     &\pm 0 &+\text{integer}   &(0,\infty)      &+\infty &\nan \\ \hline
 %     +\infty      &+0      &\multicolumn{2}{c}{$+0$}           &+1    &\multicolumn{2}{c}{$+\infty$}      &+\infty &\nan \\
 %     (1,\infty)   &+0      &\multicolumn{2}{c}{$+\abs{a}^{b}$} &+1    &\multicolumn{2}{c}{$+\abs{a}^{b}$} &+\infty &\nan \\
 %     +1           &+1      &\multicolumn{2}{c}{$+1$}           &+1    &\multicolumn{2}{c}{$+1$}           &+1      &+1   \\
 %     (0,1)        &+\infty &\multicolumn{2}{c}{$+\abs{a}^{b}$} &+1    &\multicolumn{2}{c}{$+\abs{a}^{b}$} &+0      &\nan \\
 %     +0           &+\infty &\multicolumn{2}{c}{$+\infty$}      &+1    &\multicolumn{2}{c}{$+0$}           &+0      &\nan \\
-%     -0           &+\infty &\nan          &(-1)^p\infty        &+1    &(-1)^p 0          &+0              &+0      &\nan \\
-%     (-1,0)       &+\infty &\nan          &(-1)^p\abs{a}^{b}   &+1    &(-1)^p\abs{a}^{b} &\nan            &+0      &\nan \\
-%     -1           &+1      &\nan          &(-1)^p              &+1    &(-1)^p            &\nan            &+1      &\nan \\
-%     (-\infty,-1) &+0      &\nan          &(-1)^p\abs{a}^{b}   &+1    &(-1)^p\abs{a}^{b} &\nan            &+\infty &\nan \\
-%     -\infty      &+0      &+0            &(-1)^p 0            &+1    &(-1)^p\infty      &\nan            &+\infty &\nan \\
+%     -0           &+\infty &\nan          &(-1)^b\infty        &+1    &(-1)^b 0          &+0              &+0      &\nan \\
+%     (-1,0)       &+\infty &\nan          &(-1)^b\abs{a}^{b}   &+1    &(-1)^b\abs{a}^{b} &\nan            &+0      &\nan \\
+%     -1           &+1      &\nan          &(-1)^b              &+1    &(-1)^b            &\nan            &+1      &\nan \\
+%     (-\infty,-1) &+0      &\nan          &(-1)^b\abs{a}^{b}   &+1    &(-1)^b\abs{a}^{b} &\nan            &+\infty &\nan \\
+%     -\infty      &+0      &+0            &(-1)^b 0            &+1    &(-1)^b\infty      &\nan            &+\infty &\nan \\
 %     \nan         &\nan    &\nan          &\nan                &+1    &\nan              &\nan            &\nan    &\nan \\
 %   \end{tabular}
 % \end{center}
 % We distinguished in this table the cases of finite (positive or
-% negative) exponents of the form $b=p/q$ with $q$~odd (hence
-% necessarily a power of~$5$), as $(-1)^{p/q}=(-1)^p$ is defined in that
-% case.
+% negative) integer exponents, as $(-1)^b$ is defined in that case.
 % One peculiarity of this operation is that $\nan^0 = 1^\nan = 1$,
 % because this relation is obeyed for any number, even $\pm\infty$.
 %
@@ -1189,22 +1187,18 @@
 % \begin{macro}[aux, rEXP]
 %   {
 %     \@@_pow_neg_case:w, \@@_pow_neg_case_aux:nnnnn,
-%     \@@_pow_neg_case_aux:w
+%     \@@_pow_neg_case_aux:Nnnw
 %   }
 %   This function expects a floating point number, and determines its
 %   \enquote{parity}.  It should be used after \cs{if_case:w} or in an
-%   integer expression.  It gives $-1$ if the number is an even integer
-%   divided by some power of~$5$, $0$~if the number is an odd integer
-%   divided by some power of~$5$, and $1$~otherwise.  Zeros and
+%   integer expression.  It gives $-1$ if the number is an even integer,
+%   $0$~if the number is an odd integer, and $1$~otherwise.  Zeros and
 %   $\pm\infty$ are even (because very large finite floating points are
 %   even), while \texttt{nan} is a non-integer.  The sign of normal
-%   numbers is irrelevant to parity.  The idea is to repeatedly multiply
-%   the number by~$5$ (by halving the mantissa and shifting the
-%   exponent) until the mantissa is odd (this can only happen at most
-%   $53$ times since $2^{54}>10^{16}$): if the resulting exponent is
-%   larger than $16$ the parity is even, if it is exactly $16$ the
-%   parity is odd, and otherwise we should return~$1$.  Of course there
-%   is a shortcut: we stop as soon as the exponent exceeds~$16$.
+%   numbers is irrelevant to parity.  After \cs{@@_decimate:nNnnnn} the
+%   argument |#1| of \cs{@@_pow_neg_case_aux:Nnnw} is a rounding digit,
+%   |0|~if and only if the number was an integer, and |#3| is the $8$
+%   least significant digits of that integer.
 %    \begin{macrocode}
 \cs_new:Npn \@@_pow_neg_case:w \s_@@ \@@_chk:w #1#2#3;
   {
@@ -1217,25 +1211,25 @@
     \exp_stop_f:
   }
 \cs_new:Npn \@@_pow_neg_case_aux:nnnnn #1#2#3#4#5
-  { \@@_pow_neg_case_aux:w #1 ; #2 #3 ; #4 #5 ; }
-\cs_new:Npn \@@_pow_neg_case_aux:w #1 ; #2 ; #3 ;
   {
     \if_int_compare:w #1 > \c_@@_prec_int
       -1
     \else:
+      \@@_decimate:nNnnnn { \c_@@_prec_int - #1 }
+        \@@_pow_neg_case_aux:Nnnw
+        {#2} {#3} {#4} {#5}
+    \fi:
+  }
+\cs_new:Npn \@@_pow_neg_case_aux:Nnnw #1#2#3#4 ;
+  {
+    \if_meaning:w 0 #1
       \if_int_odd:w #3 \exp_stop_f:
-        \if_int_compare:w #1 = \c_@@_prec_int
-          0
-        \else:
-          1
-        \fi:
+        0
       \else:
-        \exp_after:wN \@@_pow_neg_case_aux:w
-        \__int_value:w \__int_eval:w #1 + 1 \exp_after:wN ;
-        \__int_value:w \__int_eval:w (#2 + 1) / 2 - 1 \exp_after:wN ;
-        \__int_value:w \__int_eval:w
-          \if_int_odd:w #2 \exp_stop_f: 5000 0000 + \fi: #3 / 2 ;
+        -1
       \fi:
+    \else:
+      1
     \fi:
   }
 %    \end{macrocode}

Modified: trunk/l3kernel/testfiles/m3fp-expo001.lvt
===================================================================
--- trunk/l3kernel/testfiles/m3fp-expo001.lvt	2017-08-03 11:27:46 UTC (rev 7415)
+++ trunk/l3kernel/testfiles/m3fp-expo001.lvt	2017-08-03 11:52:22 UTC (rev 7416)
@@ -77,7 +77,7 @@
   {
     \tl_map_inline:nn { {nan} {inf} {-inf} {1} {-1} {0} {-0} }
       {
-        \tl_map_inline:nn { {nan} {inf} {-inf} {1} {-1} {0} {-0} {0.2} {-0.00128} {1.3} }
+        \tl_map_inline:nn { {nan} {inf} {-inf} {1} {-1} {0} {-0} {0.2} {-0.00128} {1.3} {12345678910} {1234567891011} }
           {
             \test:nn {#1} {##1}
           }

Modified: trunk/l3kernel/testfiles/m3fp-expo001.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3fp-expo001.tlg	2017-08-03 11:27:46 UTC (rev 7415)
+++ trunk/l3kernel/testfiles/m3fp-expo001.tlg	2017-08-03 11:52:22 UTC (rev 7416)
@@ -104,6 +104,8 @@
 '(nan)^(0.2)' = nan
 '(nan)^(-0.00128)' = nan
 '(nan)^(1.3)' = nan
+'(nan)^(12345678910)' = nan
+'(nan)^(1234567891011)' = nan
 '(inf)^(nan)' = nan
 '(inf)^(inf)' = inf
 '(inf)^(-inf)' = 0
@@ -114,6 +116,8 @@
 '(inf)^(0.2)' = inf
 '(inf)^(-0.00128)' = 0
 '(inf)^(1.3)' = inf
+'(inf)^(12345678910)' = inf
+'(inf)^(1234567891011)' = inf
 '(-inf)^(nan)' = nan
 '(-inf)^(inf)' = inf
 '(-inf)^(-inf)' = 0
@@ -121,7 +125,16 @@
 '(-inf)^(-1)' = -0
 '(-inf)^(0)' = 1
 '(-inf)^(-0)' = 1
-'(-inf)^(0.2)' = -inf
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Invalid operation (-inf)^(0.2)
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+'(-inf)^(0.2)' = nan
 '(-inf)^(-0.00128)' = 0
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
@@ -133,6 +146,8 @@
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 '(-inf)^(1.3)' = nan
+'(-inf)^(12345678910)' = inf
+'(-inf)^(1234567891011)' = -inf
 '(1)^(nan)' = 1
 '(1)^(inf)' = 1
 '(1)^(-inf)' = 1
@@ -143,6 +158,8 @@
 '(1)^(0.2)' = 1
 '(1)^(-0.00128)' = 1
 '(1)^(1.3)' = 1
+'(1)^(12345678910)' = 1
+'(1)^(1234567891011)' = 1
 '(-1)^(nan)' = nan
 '(-1)^(inf)' = 1
 '(-1)^(-inf)' = 1
@@ -150,10 +167,28 @@
 '(-1)^(-1)' = -1
 '(-1)^(0)' = 1
 '(-1)^(-0)' = 1
-'(-1)^(0.2)' = -1
-'(-1)^(-0.00128)' = 1
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
+                           Invalid operation (-1)^(0.2)
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+'(-1)^(0.2)' = nan
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Invalid operation (-1)^(-0.00128)
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+'(-1)^(-0.00128)' = nan
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
                            Invalid operation (-1)^(1.3)
 l. ...  }
 The control sequence at the end of the top line
@@ -162,6 +197,8 @@
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
 '(-1)^(1.3)' = nan
+'(-1)^(12345678910)' = 1
+'(-1)^(1234567891011)' = -1
 '(0)^(nan)' = nan
 '(0)^(inf)' = 0
 '(0)^(-inf)' = inf
@@ -190,6 +227,8 @@
 and I'll forget about whatever was undefined.
 '(0)^(-0.00128)' = inf
 '(0)^(1.3)' = 0
+'(0)^(12345678910)' = 0
+'(0)^(1234567891011)' = 0
 '(-0)^(nan)' = nan
 '(-0)^(inf)' = 0
 '(-0)^(-inf)' = inf
@@ -206,7 +245,7 @@
 '(-0)^(-1)' = -inf
 '(-0)^(0)' = 1
 '(-0)^(-0)' = 1
-'(-0)^(0.2)' = -0
+'(-0)^(0.2)' = 0
 ! Undefined control sequence.
 <argument> \LaTeX3 error: 
                            Division by zero in (-0)^(-0.00128)
@@ -216,8 +255,19 @@
 misspelled it (e.g., `\hobx'), type `I' and the correct
 spelling (e.g., `I\hbox'). Otherwise just continue,
 and I'll forget about whatever was undefined.
-'(-0)^(-0.00128)' = inf
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Invalid operation (-0)^(-0.00128)
+l. ...  }
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+'(-0)^(-0.00128)' = nan
 '(-0)^(1.3)' = 0
+'(-0)^(12345678910)' = 0
+'(-0)^(1234567891011)' = -0
 ============================================================
 ============================================================
 TEST 4: Power and minus one



More information about the latex3-commits mailing list