changeset 30031:cf60f8f636f6

Start deprecation of Fortran exponentiation operator. Replace uses of Fortran exponentiation operator (**) with regular exponentiation operator (^) in Octave code base. * NEWS: Announce deprecation. * oct-inttypes.cc: Replace uses of '**' in comments and BIST tests. * oct-sort.h: Replace uses of '**" in comments. * vectorize.m, __rotate_around_axis__.m, rotate.m, inline-fcn.tst, parser.tst: Replace uses of '**'.
author Rik <rik@octave.org>
date Tue, 24 Aug 2021 12:16:12 -0700
parents 06f4e4d986a1
children e156fce82e00
files NEWS liboctave/util/oct-inttypes.cc liboctave/util/oct-sort.h scripts/legacy/vectorize.m scripts/plot/appearance/__rotate_around_axis__.m scripts/plot/util/rotate.m test/inline-fcn.tst test/parser.tst
diffstat 8 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Sat Aug 21 21:45:19 2021 -0400
+++ b/NEWS	Tue Aug 24 12:16:12 2021 -0700
@@ -254,7 +254,7 @@
 * `ytickangle`
 * `ztickangle`
 
-### Deprecated functions and properties
+### Deprecated functions, properties, and operators
 
 The following functions and properties have been deprecated in Octave 7
 and will be removed from Octave 9 (or whatever version is the second
@@ -273,6 +273,12 @@
   Object           | Property      | Value
   -----------------|---------------|------------
                    |               |
+- Operators
+
+  Operator | Replacement | Description
+  ---------|-------------|------------
+  **       | ^           | Matrix exponent
+  .**      | .^          | Element-by-element exponent
 
 - Interpreter
 
--- a/liboctave/util/oct-inttypes.cc	Sat Aug 21 21:45:19 2021 -0400
+++ b/liboctave/util/oct-inttypes.cc	Tue Aug 24 12:16:12 2021 -0700
@@ -460,7 +460,7 @@
       // probably), the above will work as expected.  If not, it's more
       // complicated - as long as y is within _twice_ the signed range, the
       // result may still be an integer.  An instance of such an operation is
-      // 3*2**62 + (1+intmin ('int64')) that should yield int64 (2**62) + 1.
+      // 3*2^62 + (1+intmin ('int64')) that should yield int64 (2^62) + 1.
       // So what we do is to try to convert y/2 and add it twice.  Note that
       // if y/2 overflows, the result must overflow as well, and that y/2
       // cannot be a fractional number.
@@ -492,12 +492,12 @@
   else
     {
       // Again a trick to get the corner cases right.  Things like
-      // 3**2**63 - intmax ('uint64') should produce the correct result, i.e.
-      // int64 (2**63) + 1.
+      // 3^2^63 - intmax ('uint64') should produce the correct result, i.e.
+      // int64 (2^63) + 1.
       const double p2_64 = std::pow (2.0, 64);
       if (y.bool_value ())
         {
-          const uint64_t p2_64my = (~y.value ()) + 1; // Equals 2**64 - y
+          const uint64_t p2_64my = (~y.value ()) + 1; // Equals 2^64 - y
           return octave_uint64 (x - p2_64) + octave_uint64 (p2_64my);
         }
       else
@@ -530,7 +530,7 @@
 // Emulated mixed multiplications are tricky due to possible precision loss.
 // Here, after sorting out common cases for speed, we follow the strategy
 // of converting the double number into the form sign * 64-bit integer *
-// 2**exponent, multiply the 64-bit integers to get a 128-bit number, split that
+// 2^exponent, multiply the 64-bit integers to get a 128-bit number, split that
 // number into 32-bit words and form 4 double-valued summands (none of which
 // loses precision), then convert these into integers and sum them.  Though it
 // is not immediately obvious, this should work even w.r.t. rounding (none of
@@ -833,20 +833,20 @@
 
 %!assert (intmax ("int64") / intmin ("int64"), int64 (-1))
 %!assert (intmin ("int64") / int64 (-1), intmax ("int64"))
-%!assert (int64 (2**63), intmax ("int64"))
-%!assert (uint64 (2**64), intmax ("uint64"))
+%!assert (int64 (2^63), intmax ("int64"))
+%!assert (uint64 (2^64), intmax ("uint64"))
 %!test
 %! a = 1.9*2^61; b = uint64 (a); b++; assert (b > a);
 %!test
 %! a = -1.9*2^61; b = int64 (a); b++; assert (b > a);
 %!test
-%! a = int64 (-2**60) + 2; assert (1.25*a == (5*a)/4);
+%! a = int64 (-2^60) + 2; assert (1.25*a == (5*a)/4);
 %!test
-%! a = uint64 (2**61) + 2; assert (1.25*a == (5*a)/4);
-%!assert (int32 (2**31+0.5), intmax ("int32"))
-%!assert (int32 (-2**31-0.5), intmin ("int32"))
-%!assert ((int64 (2**62)+1)**1, int64 (2**62)+1)
-%!assert ((int64 (2**30)+1)**2, int64 (2**60+2**31) + 1)
+%! a = uint64 (2^61) + 2; assert (1.25*a == (5*a)/4);
+%!assert (int32 (2^31+0.5), intmax ("int32"))
+%!assert (int32 (-2^31-0.5), intmin ("int32"))
+%!assert ((int64 (2^62)+1)^1, int64 (2^62)+1)
+%!assert ((int64 (2^30)+1)^2, int64 (2^60+2^31) + 1)
 
 %!assert <54382> (uint8 (char (128)), uint8 (128))
 %!assert <54382> (uint8 (char (255)), uint8 (255))
--- a/liboctave/util/oct-sort.h	Sat Aug 21 21:45:19 2021 -0400
+++ b/liboctave/util/oct-sort.h	Tue Aug 24 12:16:12 2021 -0700
@@ -171,7 +171,7 @@
   // This is enough to sort arrays of size up to about
   //     32 * phi ** MAX_MERGE_PENDING
   // where phi ~= 1.618.  85 is ridiculously large enough, good for an array
-  // with 2**64 elements.
+  // with 2^64 elements.
   static const int MAX_MERGE_PENDING = 85;
 
   // When we get into galloping mode, we stay there until both runs win less
--- a/scripts/legacy/vectorize.m	Sat Aug 21 21:45:19 2021 -0400
+++ b/scripts/legacy/vectorize.m	Tue Aug 24 12:16:12 2021 -0700
@@ -84,11 +84,9 @@
 %! finfo = functions (vectorize (fh));
 %! assert (finfo.function, "@(x, y, z) 1e-3 .* y + 2e4 .* z");
 
-%!assert (vectorize ("2**x^5"), "2.**x.^5")
-## Note that ** is transformed to ^ by the code that prints the parse
-## tree.  I don't care too much about that...
+%!assert (vectorize ("2^x^5"), "2.^x.^5")
 %!test
-%! fh = @(x) 2**x^5;
+%! fh = @(x) 2^x^5;
 %! finfo = functions (vectorize (fh));
 %! assert (finfo.function, "@(x) 2 .^ x .^ 5");
 
--- a/scripts/plot/appearance/__rotate_around_axis__.m	Sat Aug 21 21:45:19 2021 -0400
+++ b/scripts/plot/appearance/__rotate_around_axis__.m	Tue Aug 24 12:16:12 2021 -0700
@@ -53,11 +53,11 @@
     one_m_ca = 1 - ca;
     tmp = u*x + v*y + w*z;
 
-    xr = ((a*(v**2 + w**2) - u*(b*v + c*w - tmp))*one_m_ca
+    xr = ((a*(v^2 + w^2) - u*(b*v + c*w - tmp))*one_m_ca
           + x*ca + (-c*v + b*w - w*y + v*z)*sa);
-    yr = ((b*(u**2 + w**2) - v*(a*u + c*w - tmp))*one_m_ca
+    yr = ((b*(u^2 + w^2) - v*(a*u + c*w - tmp))*one_m_ca
           + y*ca + (c*u - a*w + w*x - u*z)*sa);
-    zr = ((c*(u**2 + v**2) - w*(a*u + b*v - tmp))*one_m_ca
+    zr = ((c*(u^2 + v^2) - w*(a*u + b*v - tmp))*one_m_ca
           + z*ca + (-b*u + a*v - v*x + u*y)*sa);
   endif
 
--- a/scripts/plot/util/rotate.m	Sat Aug 21 21:45:19 2021 -0400
+++ b/scripts/plot/util/rotate.m	Tue Aug 24 12:16:12 2021 -0700
@@ -156,11 +156,11 @@
       one_m_ca = 1 - ca;
       tmp = u*x + v*y + w*z;
 
-      xr = ((a*(v**2 + w**2) - u*(b*v + c*w - tmp))*one_m_ca
+      xr = ((a*(v^2 + w^2) - u*(b*v + c*w - tmp))*one_m_ca
             + x*ca + (-c*v + b*w - w*y + v*z)*sa);
-      yr = ((b*(u**2 + w**2) - v*(a*u + c*w - tmp))*one_m_ca
+      yr = ((b*(u^2 + w^2) - v*(a*u + c*w - tmp))*one_m_ca
             + y*ca + (c*u - a*w + w*x - u*z)*sa);
-      zr = ((c*(u**2 + v**2) - w*(a*u + b*v - tmp))*one_m_ca
+      zr = ((c*(u^2 + v^2) - w*(a*u + b*v - tmp))*one_m_ca
             + z*ca + (-b*u + a*v - v*x + u*y)*sa);
     endif
 
--- a/test/inline-fcn.tst	Sat Aug 21 21:45:19 2021 -0400
+++ b/test/inline-fcn.tst	Tue Aug 24 12:16:12 2021 -0700
@@ -30,4 +30,4 @@
 
 %!assert (formula (vectorize (fn)), "x.^2 + 1")
 %!assert (formula (vectorize (inline ("1e-3*y + 2e4*z"))), "1e-3.*y + 2e4.*z")
-%!assert (formula (vectorize (inline ("2**x^5"))), "2.**x.^5")
+%!assert (formula (vectorize (inline ("2^x^5"))), "2.^x.^5")
--- a/test/parser.tst	Sat Aug 21 21:45:19 2021 -0400
+++ b/test/parser.tst	Tue Aug 24 12:16:12 2021 -0700
@@ -225,7 +225,7 @@
 ## No tests possible since a++-- is not valid
 ## Level 11 (transpose and exponentiation)
 %!test
-%! assert (2^3**2, 64);
+%! assert (2^3^2, 64);
 %! assert ([2 3].^2.', [4;9]);
 %! assert ([2 3].'.^2, [4;9]);
 %! assert (3*4i'.', 0 - 12i);