* Bug #14429 fixed - rationals r+(-r) and r-r did not simplify the denominator to... 86/17886/5
Nicolas [Thu, 10 Mar 2016 13:20:56 +0000 (14:20 +0100)]
Change-Id: I5e745c7f9529f3bae5ffca4f56853cf1c1a9fefa

scilab/CHANGES
scilab/modules/overloading/macros/%r_a_r.sci
scilab/modules/overloading/macros/%r_s_r.sci
scilab/modules/overloading/tests/nonreg_tests/bug_14429.dia.ref [new file with mode: 0644]
scilab/modules/overloading/tests/nonreg_tests/bug_14429.tst [new file with mode: 0644]

index 11cb175..43eab89 100644 (file)
@@ -333,6 +333,8 @@ In 6.0.0:
 
 * Bug #14423 fixed - bench_run did not have a return value, export file was not configurable
 
+* Bug #14429 fixed - rationals r+(-r) and r-r did not simplify the denominator to 1 in simp_mode(%t)
+
 * Bug #14433 fixed - acoth (which call atanh) crash scilab
 
 * Bug #14434 fixed - PlotSparse did not work anymore.
index 6ea63dc..28f1b6c 100644 (file)
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-function f=%r_a_r(s1,s2)
-    //f=s1+s2 s1,s2 : rational matrices
-    //author Serge Steer, INRIA
-    //!
-    if ndims(s1)<2&ndims(s2)<2 then [s1,s2]=sysconv(s1,s2),end
-    [num1,den1]=s1(["num","den"]),
-    [num2,den2]=s2(["num","den"]),
-    sz1=size(num1)
-    sz2=size(num2)
+function f = %r_a_r(s1, s2)
+    if ndims(s1)<2 & ndims(s2)<2 then
+        [s1,s2] = sysconv(s1,s2)
+    end
+    [num1,den1] = s1(["num","den"])
+    [num2,den2] = s2(["num","den"])
+    sz1 = size(num1)
+    sz2 = size(num2)
 
     if and(sz1>=0)&and(sz2>=0) then
-        num1=num1(:);den1=den1(:);
-        num2=num2(:);den2=den2(:);
+        num1 = num1(:)
+        den1 = den1(:)
+        num2 = num2(:)
+        den2 = den2(:)
 
-        if prod(sz1)==1&prod(sz2)>1 then
-            den1=den1(ones(den2))
-            num1=num1(ones(num2))
-            sz1=sz2
-        elseif prod(sz2)==1&prod(sz1)>1 then
-            den2=den2(ones(den1))
-            num2=num2(ones(num1))
-            sz2=sz1
+        if prod(sz1)==1 & prod(sz2)>1 then
+            den1 = den1(ones(den2))
+            num1 = num1(ones(num2))
+            sz1 = sz2
+        elseif prod(sz2)==1 & prod(sz1)>1 then
+            den2 = den2(ones(den1))
+            num2 = num2(ones(num1))
+            sz2 = sz1
+        end
+        if and(sz1<>sz2) then
+            error(8)
         end
-        if and(sz1<>sz2) then error(8),end
-        for l=1:prod(sz1)
-            [den,fact]=lcm([den1(l);den2(l)])
-            num1(l)=[num1(l),num2(l)]*fact
-            den1(l)=den
-        end,
-        [num1,den1]=simp(num1,den1),
-        f=rlist(matrix(num1,sz1),matrix(den1,sz1),s1.dt)
+        for l = 1:prod(sz1)
+            [den,fact] = lcm([den1(l); den2(l)])
+            num1(l) = [num1(l),num2(l)]*fact
+            den1(l) = den
+        end
+        [num1,den1] = simp(num1,den1)
+        f = rlist(matrix(num1,sz1),matrix(den1,sz1),s1.dt)
     else
-        if size(sz1,"*")>2|size(sz2,"*")>2 then error(8),end
-
-        if or(sz1<0)&or(sz2<0) then
+        if size(sz1,"*")>2|size(sz2,"*")>2 then
+            error(8)
+        end
+        if or(sz1<0) & or(sz2<0) then
             // both are eye*x
-            [den1,fact]=lcm([den1;den2])
-            [num1,den1]=simp([num1,num2]*fact,den1)
-            f=rlist(num1*eye(),den1*eye(),s1("dt")),
-        elseif  or(sz1<0) then
-            den1=den1+0;num1=num1+0
-            for l=1:min(sz2)
-                [den,fact]=lcm([den1;den2(l,l)])
-                num2(l,l)=[num1,num2(l,l)]*fact
-                den2(l,l)=den
+            [den1,fact] = lcm([den1; den2])
+            [num1,den1] = simp([num1, num2]*fact, den1)
+            f = rlist(num1*eye(),den1*eye(),s1("dt"))
+        elseif or(sz1<0) then
+            den1 = den1+0
+            num1 = num1+0
+            for l = 1:min(sz2)
+                [den,fact] = lcm([den1; den2(l,l)])
+                num2(l,l) = [num1, num2(l,l)]*fact
+                den2(l,l) = den
             end
-            [num2,den2]=simp(num2,den2),
-            f=rlist(num2,den2,s1.dt)
+            [num2,den2] = simp(num2, den2),
+            f = rlist(num2, den2, s1.dt)
         elseif or(sz2<0) then
-            den2=den2+0;num2=num2+0
-            for l=1:min(sz1)
-                [den,fact]=lcm([den1(l,l);den2])
-                num1(l,l)=[num1(l,l),num2]*fact
-                den1(l,l)=den
+            den2 = den2+0
+            num2 = num2+0
+            for l = 1:min(sz1)
+                [den,fact] = lcm([den1(l,l); den2])
+                num1(l,l) = [num1(l,l) num2]*fact
+                den1(l,l) = den
             end
-            [num1,den1]=simp(num1,den1),
-            f=rlist(num1,den1,s1.dt)
+            [num1,den1] = simp(num1,den1)
+            f = rlist(num1, den1, s1.dt)
         end
     end
-
-
+    if simp_mode()
+        f = simp(f)
+    end
 endfunction
index b959623..cb6dc75 100644 (file)
@@ -1,6 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
-//
+// Copyright (C) 2016 - Samuel GOUGEON
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-function f=%r_s_r(s1,s2)
-    //f=s1-s2 s1,s2 : rational matrices
-    //!
-    if ndims(s1)<2&ndims(s2)<2 then [s1,s2]=sysconv(s1,s2),end
-    [num1,den1]=s1(["num","den"]),
-    [num2,den2]=s2(["num","den"]),
-    sz1=size(num1)
-    sz2=size(num2)
-    if and(sz1>=0)&and(sz2>=0) then
-        num1=num1(:);den1=den1(:);
-        num2=num2(:);den2=den2(:);
-
-        if prod(sz1)==1&prod(sz2)>1 then
-            den1=den1(ones(den2))
-            num1=num1(ones(num2))
-            sz1=sz2
-        elseif prod(sz2)==1&prod(sz1)>1 then
-            den2=den2(ones(den1))
-            num2=num2(ones(num1))
-            sz2=sz1
-        end
-        if and(sz1<>sz2) then error(8),end
-        for l=1:prod(sz1)
-            [den,fact]=lcm([den1(l);den2(l)])
-            num1(l)=[num1(l),-num2(l)]*fact
-            den1(l)=den
-        end,
-        [num1,den1]=simp(num1,den1),
-        f=rlist(matrix(num1,sz1),matrix(den1,sz1),s1.dt)
-    else
-
-        if size(sz1,"*")>2|size(sz2,"*")>2 then error(8),end
-
-        if or(sz1<0)&or(sz2<0) then
-            // both are eye*x
-            [den1,fact]=lcm([den1;den2])
-            [num1,den1]=simp([num1,-num2]*fact,den1)
-            f=rlist(num1*eye(),den1*eye(),s1("dt")),
-        elseif  or(sz1<0) then
-            den1=den1+0;num1=num1+0
-            for l=1:min(sz2)
-                [den,fact]=lcm([den1;den2(l,l)])
-                num2(l,l)=[num1,-num2(l,l)]*fact
-                den2(l,l)=den
-            end
-            [num2,den2]=simp(num2,den2),
-            f=rlist(num2,den2,s1.dt)
-        elseif or(sz2<0) then
-            den2=den2+0;num2=num2+0
-            for l=1:min(sz1)
-                [den,fact]=lcm([den1(l,l);den2])
-                num1(l,l)=[num1(l,l),-num2]*fact
-                den1(l,l)=den
-            end
-            [num1,den1]=simp(num1,den1),
-            f=rlist(num1,den1,s1.dt)
-        end
-    end
+function f = %r_s_r(s1, s2)
+    s2.num = -s2.num
+    f = s1 + s2
 endfunction
diff --git a/scilab/modules/overloading/tests/nonreg_tests/bug_14429.dia.ref b/scilab/modules/overloading/tests/nonreg_tests/bug_14429.dia.ref
new file mode 100644 (file)
index 0000000..47d7498
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- Non-regression test for bug 14429 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/14429
+//
+// <-- Short Description -->
+// With a rational r in simp_mode(%t), r-r and r+(-r) dit not simplify the denominator to 1
+sm = simp_mode();
+simp_mode(%t);
+r = 1/(%i-%z)^3;
+s = r-r;
+assert_checkequal(s.den, poly(1,"z","coeff"));
+a = r+(-r);
+assert_checkequal(a.den, poly(1,"z","coeff"));
+simp_mode(sm);
diff --git a/scilab/modules/overloading/tests/nonreg_tests/bug_14429.tst b/scilab/modules/overloading/tests/nonreg_tests/bug_14429.tst
new file mode 100644 (file)
index 0000000..ea4d1c3
--- /dev/null
@@ -0,0 +1,22 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- Non-regression test for bug 14429 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/14429
+//
+// <-- Short Description -->
+// With a rational r in simp_mode(%t), r-r and r+(-r) dit not simplify the denominator to 1
+
+sm = simp_mode();
+simp_mode(%t);
+r = 1/(%i-%z)^3;
+s = r-r;
+assert_checkequal(s.den, poly(1,"z","coeff"));
+a = r+(-r);
+assert_checkequal(a.den, poly(1,"z","coeff"));
+simp_mode(sm);