From b662c586207e1088e3a8ce46724fa8e87c6c9f71 Mon Sep 17 00:00:00 2001 From: Samuel GOUGEON Date: Tue, 2 Aug 2016 00:42:10 +0200 Subject: [PATCH] * Bug #14649 fixed: isnan(complex(%inf, %inf)) was %F while phase is NaN http://bugzilla.scilab.org/14649 Change-Id: Ib925be0f43dd9300b764b776e3be8fe8a0c48ae1 --- scilab/CHANGES.md | 1 + .../modules/elementary_functions/macros/isnan.sci | 18 +++++- .../tests/nonreg_tests/bug_14649.dia.ref | 19 ++++++ .../tests/nonreg_tests/bug_14649.tst | 20 +++++++ .../tests/unit_tests/isnan.dia.ref | 54 +++++++++++++++++ .../tests/unit_tests/isnan.tst | 62 ++++++++++++++++++++ 6 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.dia.ref create mode 100644 scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.tst create mode 100644 scilab/modules/elementary_functions/tests/unit_tests/isnan.dia.ref create mode 100644 scilab/modules/elementary_functions/tests/unit_tests/isnan.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 4bfc446..050b60a 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -263,6 +263,7 @@ Bug Fixes * [Bug #14648](http://bugzilla.scilab.org/show_bug.cgi?id=14648) fixed - `isinf` returned `%F` for complex numbers with both real and imag infinite parts. * [Bug #14662](http://bugzilla.scilab.org/show_bug.cgi?id=14662) fixed - Matrix of strings concatenation with single quote led to a parser error. * [Bug #14681](http://bugzilla.scilab.org/show_bug.cgi?id=14681) fixed - Short-circuited AND operation was not possible with double matrices in if and while clauses +* [Bug #14649](http://bugzilla.scilab.org/show_bug.cgi?id=14649) fixed - isnan(complex(%inf, %inf)) returned %F while the phase is NaN. ### In 6.0.0 beta-2 and earlier: diff --git a/scilab/modules/elementary_functions/macros/isnan.sci b/scilab/modules/elementary_functions/macros/isnan.sci index 885e5e6..ac9c2a1 100644 --- a/scilab/modules/elementary_functions/macros/isnan.sci +++ b/scilab/modules/elementary_functions/macros/isnan.sci @@ -1,6 +1,7 @@ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) INRIA // Copyright (C) DIGITEO - 2011 - Allan CORNET +// Copyright (C) 2016 - Samuel GOUGEON // // Copyright (C) 2012 - 2016 - Scilab Enterprises // @@ -14,11 +15,24 @@ function r = isnan(x) rhs = argn(2); if rhs <> 1 then - error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"isnan", 1)); + msg = gettext("%s: Wrong number of input argument(s): %d expected.\n") + error(msprintf(msg, "isnan", 1)); end if x == [] then r = []; else - r =~ (x == x); + if or(type(x)==[1 5]) // for dense and sparse decimal encodings + if isreal(x) + r = (x ~= x); + else + rp = real(x) + ip = imag(x) + r = (x~=x | (abs(real(x))==%inf & abs(imag(x))==%inf) ) + end + else + r = ~(x == x); + // the case of polynomials will be better managed apart, + // after merging this first fix for complex numbers + end end endfunction diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.dia.ref b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.dia.ref new file mode 100644 index 0000000..11d6a71 --- /dev/null +++ b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.dia.ref @@ -0,0 +1,19 @@ +// ============================================================================= +// 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. +// ============================================================================= +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 14649 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=14649 +// +// <-- Short Description --> +// isnan(complex(%inf, %inf)) returned %F +C = complex([-%inf -%inf %inf %inf], [-%inf %inf -%inf %inf]); +res = [%t %t %t %t]; +assert_checkequal(isnan(C), res); +assert_checkequal(isnan(sparse(C)), sparse(res)); diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.tst b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.tst new file mode 100644 index 0000000..35d8967 --- /dev/null +++ b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_14649.tst @@ -0,0 +1,20 @@ +// ============================================================================= +// 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. +// ============================================================================= +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 14649 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=14649 +// +// <-- Short Description --> +// isnan(complex(%inf, %inf)) returned %F + +C = complex([-%inf -%inf %inf %inf], [-%inf %inf -%inf %inf]); +res = [%t %t %t %t]; +assert_checkequal(isnan(C), res); +assert_checkequal(isnan(sparse(C)), sparse(res)); diff --git a/scilab/modules/elementary_functions/tests/unit_tests/isnan.dia.ref b/scilab/modules/elementary_functions/tests/unit_tests/isnan.dia.ref new file mode 100644 index 0000000..a49b465 --- /dev/null +++ b/scilab/modules/elementary_functions/tests/unit_tests/isnan.dia.ref @@ -0,0 +1,54 @@ +// ============================================================================= +// 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. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// unit tests for isnan() function +// =============================== +assert_checkequal(isnan([]), []); +// With decimal real numbers +// ------------------------- +assert_checktrue(isnan(%nan)); +M = [%pi %inf -1 %nan 3 -%nan -%inf]; +R = [%f %f %f %t %f %t %f]; +assert_checkequal(isnan(M), R); +assert_checkequal(isnan(M'),R'); +M = sparse(M); +R = sparse(R); +assert_checkequal(isnan(M), R); +assert_checkequal(isnan(M'),R'); +M = [%pi %inf -1 %nan + 3 -%nan 0 -%inf]; +R = [%f %f %f %t ; %f %t %f %f]; +assert_checkequal(isnan(M),R); +M = sparse(M); +R = sparse(R); +assert_checkequal(isnan(M), R); +clear M R +M(:,:,1) = [%pi %inf ; -1 %nan]; +M(:,:,2) = [ 3 -%nan ; 0 -%inf]; +R(:,:,1) = [%f %f ; %f %t ]; +R(:,:,2) = [%f %t ; %f %f ]; +assert_checkequal(isnan(M),R); +// no sparse hypermatrix +// With complex numbers +// -------------------- +G = [ -%inf -10 0 %nan 10 %inf]; +[R,I] = meshgrid(G,G); +C = complex(R,I); +res = [ + 1. 0. 0. 1. 0. 1. + 0. 0. 0. 1. 0. 0. + 0. 0. 0. 1. 0. 0. + 1. 1. 1. 1. 1. 1. + 0. 0. 0. 1. 0. 0. + 1. 0. 0. 1. 0. 1. + ]==1; +assert_checkequal(isnan(C), res); +C = sparse(C); +res = sparse(res); +assert_checkequal(isnan(C), res); diff --git a/scilab/modules/elementary_functions/tests/unit_tests/isnan.tst b/scilab/modules/elementary_functions/tests/unit_tests/isnan.tst new file mode 100644 index 0000000..ff1ef79 --- /dev/null +++ b/scilab/modules/elementary_functions/tests/unit_tests/isnan.tst @@ -0,0 +1,62 @@ +// ============================================================================= +// 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. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// unit tests for isnan() function +// =============================== + +assert_checkequal(isnan([]), []); + +// With decimal real numbers +// ------------------------- +assert_checktrue(isnan(%nan)); + +M = [%pi %inf -1 %nan 3 -%nan -%inf]; +R = [%f %f %f %t %f %t %f]; +assert_checkequal(isnan(M), R); +assert_checkequal(isnan(M'),R'); +M = sparse(M); +R = sparse(R); +assert_checkequal(isnan(M), R); +assert_checkequal(isnan(M'),R'); + +M = [%pi %inf -1 %nan + 3 -%nan 0 -%inf]; +R = [%f %f %f %t ; %f %t %f %f]; +assert_checkequal(isnan(M),R); +M = sparse(M); +R = sparse(R); +assert_checkequal(isnan(M), R); + +clear M R +M(:,:,1) = [%pi %inf ; -1 %nan]; +M(:,:,2) = [ 3 -%nan ; 0 -%inf]; +R(:,:,1) = [%f %f ; %f %t ]; +R(:,:,2) = [%f %t ; %f %f ]; +assert_checkequal(isnan(M),R); +// no sparse hypermatrix + +// With complex numbers +// -------------------- +G = [ -%inf -10 0 %nan 10 %inf]; +[R,I] = meshgrid(G,G); +C = complex(R,I); +res = [ + 1. 0. 0. 1. 0. 1. + 0. 0. 0. 1. 0. 0. + 0. 0. 0. 1. 0. 0. + 1. 1. 1. 1. 1. 1. + 0. 0. 0. 1. 0. 0. + 1. 0. 0. 1. 0. 1. + ]==1; +assert_checkequal(isnan(C), res); + +C = sparse(C); +res = sparse(res); +assert_checkequal(isnan(C), res); + -- 1.7.9.5