diff options
author | Stéphane MOTTELET <stephane.mottelet@utc.fr> | 2019-09-18 12:13:44 +0200 |
---|---|---|
committer | Clément DAVID <clement.david@esi-group.com> | 2019-11-19 22:36:42 +0100 |
commit | d79ab01128a04f7776503d4f3b7a5e250a113c34 (patch) | |
tree | fe4c2bfe881bdd5820b4d2e43a16c20cd08bee05 | |
parent | d76fdfbfc4c43364f9cb29b44d7a9ff36759d6ae (diff) | |
download | scilab-d79ab01128a04f7776503d4f3b7a5e250a113c34.zip scilab-d79ab01128a04f7776503d4f3b7a5e250a113c34.tar.gz |
* Bug 15781 fixed: display of complex matrix was ugly
https://bugzilla.scilab.org/show_bug.cgi?id=15781
This patch strictly adresses the complex display problem.
Alignment is fixed and homegeneity is obtained by always displaying
a real and an imaginary part even when both are zero in all cases:
scalar, vector and matrix.
Change-Id: I1bb92a5387bbd939d998b1ae7e9fc6df46c30528
-rw-r--r-- | scilab/CHANGES.md | 1 | ||||
-rw-r--r-- | scilab/modules/ast/includes/types/tostring_common.hxx | 2 | ||||
-rw-r--r-- | scilab/modules/ast/src/cpp/types/double.cpp | 180 | ||||
-rw-r--r-- | scilab/modules/ast/src/cpp/types/tostring_common.cpp | 142 | ||||
-rw-r--r-- | scilab/modules/ast/tests/nonreg_tests/bug_15781.dia.ref | 172 | ||||
-rw-r--r-- | scilab/modules/ast/tests/nonreg_tests/bug_15781.tst | 45 |
6 files changed, 282 insertions, 260 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 8df34ab..33d3866 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md | |||
@@ -162,6 +162,7 @@ Bug Fixes | |||
162 | * [#15577](http://bugzilla.scilab.org/show_bug.cgi?id=15577): `edit` did not accept a line number as text, as with `edit linspace 21`. | 162 | * [#15577](http://bugzilla.scilab.org/show_bug.cgi?id=15577): `edit` did not accept a line number as text, as with `edit linspace 21`. |
163 | * [#15668](http://bugzilla.scilab.org/show_bug.cgi?id=15668): `save(filename)` saved all predefined Scilab constants %e %pi etc.. (regression) | 163 | * [#15668](http://bugzilla.scilab.org/show_bug.cgi?id=15668): `save(filename)` saved all predefined Scilab constants %e %pi etc.. (regression) |
164 | * [#15715](http://bugzilla.scilab.org/show_bug.cgi?id=15715): `%nan` indices crashed Scilab. | 164 | * [#15715](http://bugzilla.scilab.org/show_bug.cgi?id=15715): `%nan` indices crashed Scilab. |
165 | * [#15581](http://bugzilla.scilab.org/show_bug.cgi?id=15581): display of complex matrix was ugly. | ||
165 | * [#15812](http://bugzilla.scilab.org/show_bug.cgi?id=15812): On assigning variables the source variable may become become corrupted | 166 | * [#15812](http://bugzilla.scilab.org/show_bug.cgi?id=15812): On assigning variables the source variable may become become corrupted |
166 | * [#15840](http://bugzilla.scilab.org/show_bug.cgi?id=15840): `grand(1,"prm",m)` yielded an unsqueezed size([size(m) 1]) hypermatrix | 167 | * [#15840](http://bugzilla.scilab.org/show_bug.cgi?id=15840): `grand(1,"prm",m)` yielded an unsqueezed size([size(m) 1]) hypermatrix |
167 | * [#15964](http://bugzilla.scilab.org/show_bug.cgi?id=15954): A complex empty sparse matrix could be obtained after insertion. | 168 | * [#15964](http://bugzilla.scilab.org/show_bug.cgi?id=15954): A complex empty sparse matrix could be obtained after insertion. |
diff --git a/scilab/modules/ast/includes/types/tostring_common.hxx b/scilab/modules/ast/includes/types/tostring_common.hxx index b728bc4..92cc312 100644 --- a/scilab/modules/ast/includes/types/tostring_common.hxx +++ b/scilab/modules/ast/includes/types/tostring_common.hxx | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "os_string.h" | 21 | #include "os_string.h" |
22 | #include "dynlib_ast.h" | 22 | #include "dynlib_ast.h" |
23 | 23 | ||
24 | #define BLANK_SIZE 1 | ||
24 | #define SIZE_BETWEEN_TWO_VALUES 1 | 25 | #define SIZE_BETWEEN_TWO_VALUES 1 |
25 | #define SPACE_BETWEEN_TWO_VALUES L" " | 26 | #define SPACE_BETWEEN_TWO_VALUES L" " |
26 | #define SIZE_BOOL 1 | 27 | #define SIZE_BOOL 1 |
@@ -31,6 +32,7 @@ | |||
31 | #define MINUS_STRING L"-" | 32 | #define MINUS_STRING L"-" |
32 | #define PLUS_STRING L"+" | 33 | #define PLUS_STRING L"+" |
33 | #define SYMBOL_I L"i" | 34 | #define SYMBOL_I L"i" |
35 | #define SIZE_SYMBOL_I 1 | ||
34 | 36 | ||
35 | 37 | ||
36 | #define MAX_LINES 100 | 38 | #define MAX_LINES 100 |
diff --git a/scilab/modules/ast/src/cpp/types/double.cpp b/scilab/modules/ast/src/cpp/types/double.cpp index e57ba36..c6f31f2 100644 --- a/scilab/modules/ast/src/cpp/types/double.cpp +++ b/scilab/modules/ast/src/cpp/types/double.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | 2 | * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab |
3 | * Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS | 3 | * Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS |
4 | * | 4 | * Copyright (C) 2019 - Stéphane MOTTELET |
5 | * Copyright (C) 2012 - 2016 - Scilab Enterprises | 5 | * Copyright (C) 2012 - 2016 - Scilab Enterprises |
6 | * | 6 | * |
7 | * This file is hereby licensed under the terms of the GNU GPL v2.0, | 7 | * This file is hereby licensed under the terms of the GNU GPL v2.0, |
@@ -392,152 +392,22 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
392 | ostr << std::endl; | 392 | ostr << std::endl; |
393 | } | 393 | } |
394 | } | 394 | } |
395 | else if (getCols() == 1) | ||
396 | { | ||
397 | //column vector | ||
398 | if (isComplex() == false) | ||
399 | { | ||
400 | for (int i = m_iRows1PrintState ; i < getRows() ; i++) | ||
401 | { | ||
402 | iCurrentLine++; | ||
403 | if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines)) | ||
404 | { | ||
405 | // Number of lines to print exceeds the max lines allowed | ||
406 | // Record what line we were at | ||
407 | m_iRows1PrintState = i; | ||
408 | return false; | ||
409 | } | ||
410 | |||
411 | _piDims[1] = 0; | ||
412 | _piDims[0] = i; | ||
413 | int iPos = getIndex(_piDims); | ||
414 | |||
415 | printDoubleValue(ostr, m_pRealData[iPos]); | ||
416 | ostr << std::endl; | ||
417 | } | ||
418 | } | ||
419 | else | ||
420 | { | ||
421 | for (int i = m_iRows1PrintState ; i < getRows() ; i++) | ||
422 | { | ||
423 | //complex value | ||
424 | iCurrentLine++; | ||
425 | if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines)) | ||
426 | { | ||
427 | m_iRows1PrintState = i; | ||
428 | return false; | ||
429 | } | ||
430 | |||
431 | _piDims[1] = 0; | ||
432 | _piDims[0] = i; | ||
433 | int iPos = getIndex(_piDims); | ||
434 | |||
435 | printComplexValue(ostr, m_pRealData[iPos], m_pImgData[iPos]); | ||
436 | ostr << std::endl; | ||
437 | } | ||
438 | } | ||
439 | } | ||
440 | else if (getRows() == 1) | ||
441 | { | ||
442 | //row vector | ||
443 | std::wostringstream ostemp; | ||
444 | int iLastVal = m_iCols1PrintState; | ||
445 | |||
446 | if (isComplex() == false) | ||
447 | { | ||
448 | int iLen = 0; | ||
449 | for (int i = m_iCols1PrintState ; i < getCols() ; i++) | ||
450 | { | ||
451 | _piDims[0] = 0; | ||
452 | _piDims[1] = i; | ||
453 | int iPos = getIndex(_piDims); | ||
454 | |||
455 | DoubleFormat df; | ||
456 | // Get the size of the column to print | ||
457 | getDoubleFormat(ZeroIsZero(m_pRealData[iPos]), &df); | ||
458 | iLen = static_cast<int>(ostemp.str().size()) + SIZE_BETWEEN_TWO_VALUES + df.iSignLen + df.iWidth; | ||
459 | if (iLen >= iLineLen - 1 && iLastVal != i) | ||
460 | { | ||
461 | //Max length, new line | ||
462 | iCurrentLine += 4; //"column x to Y" + empty line + value + empty line | ||
463 | if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines)) | ||
464 | { | ||
465 | // Number of lines to print exceeds the max lines allowed | ||
466 | // Record what column we were at | ||
467 | m_iCols1PrintState = iLastVal; | ||
468 | return false; | ||
469 | } | ||
470 | |||
471 | addColumnString(ostr, iLastVal + 1, i); | ||
472 | ostr << ostemp.str() << std::endl; | ||
473 | ostemp.str(L""); | ||
474 | iLastVal = i; | ||
475 | } | ||
476 | |||
477 | ostemp << SPACE_BETWEEN_TWO_VALUES; | ||
478 | addDoubleValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), &df); | ||
479 | } | ||
480 | |||
481 | if (iLastVal != 0) | ||
482 | { | ||
483 | addColumnString(ostr, iLastVal + 1, getCols()); | ||
484 | } | ||
485 | ostemp << std::endl; | ||
486 | ostr << ostemp.str(); | ||
487 | } | ||
488 | else //complex case | ||
489 | { | ||
490 | int iTotalLen = 0; | ||
491 | int iLen = 0; | ||
492 | |||
493 | for (int i = m_iCols1PrintState ; i < getCols() ; i++) | ||
494 | { | ||
495 | _piDims[0] = 0; | ||
496 | _piDims[1] = i; | ||
497 | int iPos = getIndex(_piDims); | ||
498 | |||
499 | DoubleFormat dfR, dfI; | ||
500 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalLen, &dfR, &dfI); | ||
501 | iLen = static_cast<int>(ostemp.str().size()) + SIZE_BETWEEN_TWO_VALUES + iTotalLen; | ||
502 | if (iLen >= iLineLen - 1 && iLastVal != i) | ||
503 | { | ||
504 | //Max length, new line | ||
505 | iCurrentLine += 4; //"column x to Y" + empty line + value + empty line | ||
506 | if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines)) | ||
507 | { | ||
508 | // Number of lines to print exceeds the max lines allowed | ||
509 | // Record what column we were at | ||
510 | m_iCols1PrintState = iLastVal; | ||
511 | return false; | ||
512 | } | ||
513 | |||
514 | addColumnString(ostr, iLastVal + 1, i); | ||
515 | ostr << ostemp.str() << std::endl; | ||
516 | ostemp.str(L""); | ||
517 | iLastVal = i; | ||
518 | } | ||
519 | |||
520 | ostemp << SPACE_BETWEEN_TWO_VALUES; | ||
521 | addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), iTotalLen, &dfR, &dfI); | ||
522 | } | ||
523 | |||
524 | if (iLastVal != 0) | ||
525 | { | ||
526 | addColumnString(ostr, iLastVal + 1, getCols()); | ||
527 | } | ||
528 | ostemp << std::endl; | ||
529 | ostr << ostemp.str(); | ||
530 | } | ||
531 | } | ||
532 | else // matrix | 395 | else // matrix |
533 | { | 396 | { |
534 | std::wostringstream ostemp; | 397 | std::wostringstream ostemp; |
535 | int iLen = 0; | 398 | int iLen = SIZE_BETWEEN_TWO_VALUES; |
536 | int iLastCol = m_iCols1PrintState; | 399 | int iLastCol = m_iCols1PrintState; |
400 | // some unchanging field is to be retrieved for later used | ||
401 | DoubleFormat df; | ||
402 | int iBlankSize = df.bPrintBlank ? BLANK_SIZE : 0; | ||
537 | 403 | ||
538 | //Array with the max printed size of each col | 404 | //Array with the max printed size of each col |
539 | int *piSize = new int[getCols()]; | 405 | int *piSize = new int[getCols()]; |
406 | int *piRSize = new int[getCols()]; | ||
407 | int *piISize = new int[getCols()]; | ||
540 | memset(piSize, 0x00, getCols() * sizeof(int)); | 408 | memset(piSize, 0x00, getCols() * sizeof(int)); |
409 | memset(piRSize, 0x00, getCols() * sizeof(int)); | ||
410 | memset(piISize, 0x00, getCols() * sizeof(int)); | ||
541 | 411 | ||
542 | if (isComplex() == false) | 412 | if (isComplex() == false) |
543 | { | 413 | { |
@@ -597,7 +467,7 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
597 | ostemp << std::endl; | 467 | ostemp << std::endl; |
598 | } | 468 | } |
599 | 469 | ||
600 | iLen = 0; | 470 | iLen = SIZE_BETWEEN_TWO_VALUES; |
601 | 471 | ||
602 | iCurrentLine++; | 472 | iCurrentLine++; |
603 | if (m_iRows2PrintState == 0) | 473 | if (m_iRows2PrintState == 0) |
@@ -612,7 +482,7 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
612 | m_iCols1PrintState = 0; | 482 | m_iCols1PrintState = 0; |
613 | } | 483 | } |
614 | 484 | ||
615 | iLen += piSize[iCols1] + SIGN_LENGTH + SIZE_BETWEEN_TWO_VALUES; | 485 | iLen += piSize[iCols1] + SIZE_BETWEEN_TWO_VALUES + iBlankSize; |
616 | } | 486 | } |
617 | 487 | ||
618 | for (int iRows2 = m_iRows2PrintState ; iRows2 < getRows() ; iRows2++) | 488 | for (int iRows2 = m_iRows2PrintState ; iRows2 < getRows() ; iRows2++) |
@@ -669,13 +539,10 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
669 | 539 | ||
670 | DoubleFormat dfR, dfI; | 540 | DoubleFormat dfR, dfI; |
671 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI); | 541 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI); |
672 | 542 | // keep track of real and imaginary part width for further alignment | |
673 | iTotalWidth += (dfR.iWidth == 0 ? 0 : SIGN_LENGTH) + (dfI.iWidth == 0 ? 0 : SIGN_LENGTH + 1); | 543 | piISize[iCols1] = std::max(piISize[iCols1], dfI.iWidth); |
674 | if (iTotalWidth > piSize[iCols1]) | 544 | piRSize[iCols1] = std::max(piRSize[iCols1], dfR.iWidth); |
675 | { | 545 | piSize[iCols1] = std::max(piSize[iCols1], iTotalWidth); |
676 | piSize[iCols1] = iTotalWidth; | ||
677 | } | ||
678 | |||
679 | } | 546 | } |
680 | } | 547 | } |
681 | 548 | ||
@@ -700,6 +567,8 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
700 | m_iRows2PrintState = iRows2; | 567 | m_iRows2PrintState = iRows2; |
701 | m_iCols1PrintState = iLastCol; | 568 | m_iCols1PrintState = iLastCol; |
702 | delete[] piSize; | 569 | delete[] piSize; |
570 | delete[] piRSize; | ||
571 | delete[] piISize; | ||
703 | return false; | 572 | return false; |
704 | } | 573 | } |
705 | 574 | ||
@@ -713,13 +582,16 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
713 | DoubleFormat dfR, dfI; | 582 | DoubleFormat dfR, dfI; |
714 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI); | 583 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI); |
715 | 584 | ||
585 | // override with precomputed real part width for alignment of imaginary part sign | ||
586 | dfR.iWidth = piRSize[iCols2]; | ||
587 | dfI.iWidth = piISize[iCols2]; | ||
716 | ostemp << SPACE_BETWEEN_TWO_VALUES; | 588 | ostemp << SPACE_BETWEEN_TWO_VALUES; |
717 | addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), piSize[iCols2], &dfR, &dfI); | 589 | addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), piSize[iCols2], &dfR, &dfI); |
718 | } | 590 | } |
719 | ostemp << std::endl; | 591 | ostemp << std::endl; |
720 | } | 592 | } |
721 | 593 | ||
722 | iLen = 0; | 594 | iLen = SIZE_BETWEEN_TWO_VALUES; |
723 | 595 | ||
724 | iCurrentLine++; | 596 | iCurrentLine++; |
725 | if (m_iRows2PrintState == 0) | 597 | if (m_iRows2PrintState == 0) |
@@ -752,6 +624,7 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
752 | m_iRows2PrintState = iRows2; | 624 | m_iRows2PrintState = iRows2; |
753 | m_iCols1PrintState = iLastCol; | 625 | m_iCols1PrintState = iLastCol; |
754 | delete[] piSize; | 626 | delete[] piSize; |
627 | delete[] piRSize; | ||
755 | return false; | 628 | return false; |
756 | } | 629 | } |
757 | 630 | ||
@@ -765,8 +638,11 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
765 | DoubleFormat dfR, dfI; | 638 | DoubleFormat dfR, dfI; |
766 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI); | 639 | getComplexFormat(ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), &iTotalWidth, &dfR, &dfI); |
767 | 640 | ||
641 | // override with precomputed real part width for aligment of imaginary part sign | ||
642 | dfR.iWidth = piRSize[iCols2]; | ||
643 | dfI.iWidth = piISize[iCols2]; | ||
768 | ostemp << SPACE_BETWEEN_TWO_VALUES; | 644 | ostemp << SPACE_BETWEEN_TWO_VALUES; |
769 | addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), piSize[iCols2], &dfR, &dfI); | 645 | addDoubleComplexValue(&ostemp, ZeroIsZero(m_pRealData[iPos]), ZeroIsZero(m_pImgData[iPos]), piSize[iCols2], &dfR, &dfI); |
770 | } | 646 | } |
771 | ostemp << std::endl; | 647 | ostemp << std::endl; |
772 | } | 648 | } |
@@ -779,6 +655,8 @@ bool Double::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i | |||
779 | } | 655 | } |
780 | 656 | ||
781 | delete[] piSize; | 657 | delete[] piSize; |
658 | delete[] piRSize; | ||
659 | delete[] piISize; | ||
782 | } | 660 | } |
783 | 661 | ||
784 | return true; | 662 | return true; |
diff --git a/scilab/modules/ast/src/cpp/types/tostring_common.cpp b/scilab/modules/ast/src/cpp/types/tostring_common.cpp index 1084e74..0badf9e 100644 --- a/scilab/modules/ast/src/cpp/types/tostring_common.cpp +++ b/scilab/modules/ast/src/cpp/types/tostring_common.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | 2 | * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab |
3 | * Copyright (C) 2009 - DIGITEO - Antoine ELIAS | 3 | * Copyright (C) 2009 - DIGITEO - Antoine ELIAS |
4 | * Copyright (C) 2018 - Stéphane MOTTELET | 4 | * Copyright (C) 2018 - 2019 - Stéphane MOTTELET |
5 | * | 5 | * |
6 | * Copyright (C) 2012 - 2016 - Scilab Enterprises | 6 | * Copyright (C) 2012 - 2016 - Scilab Enterprises |
7 | * | 7 | * |
@@ -28,10 +28,8 @@ extern "C" | |||
28 | #include "os_string.h" | 28 | #include "os_string.h" |
29 | #include "dtoa.h" | 29 | #include "dtoa.h" |
30 | #include "charEncoding.h" | 30 | #include "charEncoding.h" |
31 | #include "sciprint.h" | ||
32 | } | 31 | } |
33 | 32 | ||
34 | #define BLANK_SIZE 1 | ||
35 | #define POINT_SIZE 1 | 33 | #define POINT_SIZE 1 |
36 | #define EXPOSANT_SIZE 2 //exposant symbol + exposant sign | 34 | #define EXPOSANT_SIZE 2 //exposant symbol + exposant sign |
37 | 35 | ||
@@ -182,38 +180,8 @@ void getComplexFormat(double _dblR, double _dblI, int *_piTotalWidth, DoubleForm | |||
182 | { | 180 | { |
183 | getDoubleFormat(_dblR, _pDFR); | 181 | getDoubleFormat(_dblR, _pDFR); |
184 | getDoubleFormat(_dblI, _pDFI); | 182 | getDoubleFormat(_dblI, _pDFI); |
185 | 183 | ||
186 | *_piTotalWidth = 0; | 184 | *_piTotalWidth = _pDFR->iWidth + _pDFI->iWidth + 2*(_pDFR->bPrintBlank ? BLANK_SIZE : 0) + BLANK_SIZE + SIZE_SYMBOL_I; |
187 | if (isRealZero(_dblI)) | ||
188 | { | ||
189 | if (isRealZero(_dblR)) | ||
190 | { | ||
191 | *_piTotalWidth += 1; //"0" | ||
192 | _pDFI->iWidth = 0; | ||
193 | _pDFI->iSignLen = 0; | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | *_piTotalWidth += _pDFR->iWidth; | ||
198 | _pDFI->iWidth = 0; | ||
199 | _pDFI->iSignLen = 0; | ||
200 | } | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | if (isRealZero(_dblR)) | ||
205 | { | ||
206 | *_piTotalWidth += _pDFI->iWidth; | ||
207 | _pDFR->iWidth = 0; | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | *_piTotalWidth += _pDFR->iWidth + _pDFI->iWidth; | ||
212 | } | ||
213 | |||
214 | // i character | ||
215 | *_piTotalWidth += 1; | ||
216 | } | ||
217 | } | 185 | } |
218 | 186 | ||
219 | void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * _pDF) | 187 | void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * _pDF) |
@@ -331,16 +299,16 @@ void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * | |||
331 | { | 299 | { |
332 | if (_pDF->bPrintPoint) | 300 | if (_pDF->bPrintPoint) |
333 | { | 301 | { |
334 | /* str.append(std::max(0, (ConfigVariable::getFormatSize() - (int)str.length()))-1, '0'); */ | 302 | /*str.append(std::max(0, (ConfigVariable::getFormatSize() - (int)str.length()))-1, '0');*/ |
335 | } | 303 | } |
336 | else | 304 | else |
337 | { | 305 | { |
338 | iWidth = 1+str.length(); | 306 | iWidth = 1 + str.length(); |
339 | } | 307 | } |
340 | } | 308 | } |
341 | 309 | ||
342 | wchar_t* pwstData = to_wide_string(str.data()); | 310 | wchar_t* pwstData = to_wide_string(str.data()); |
343 | os_swprintf(pwstOutput, 32, L"%ls%-*ls", pwstSign, iWidth-1, pwstData); | 311 | os_swprintf(pwstOutput, 32, L"%ls%-*ls", pwstSign, iWidth - 1, pwstData); |
344 | FREE(pwstData); | 312 | FREE(pwstData); |
345 | } | 313 | } |
346 | else if (wcslen(pwstSign) != 0) | 314 | else if (wcslen(pwstSign) != 0) |
@@ -375,80 +343,36 @@ void addDoubleComplexValue(std::wostringstream * _postr, double _dblR, double _d | |||
375 | */ | 343 | */ |
376 | 344 | ||
377 | // *_postr << "|%" << _iTotalWitdh << "%|"; | 345 | // *_postr << "|%" << _iTotalWitdh << "%|"; |
378 | if (_dblR == 0) | ||
379 | { | ||
380 | //no real part | ||
381 | if (_dblI == 0) | ||
382 | { | ||
383 | //no imaginary part | ||
384 | 346 | ||
385 | //0 | 347 | //R |
386 | DoubleFormat df; | 348 | DoubleFormat df; |
387 | 349 | ||
388 | addDoubleValue(&ostemp, 0, &df); | 350 | df.iPrec = _pDFR->iPrec; |
389 | } | 351 | df.bExp = _pDFR->bExp; |
390 | else | ||
391 | { | ||
392 | //imaginary part | ||
393 | |||
394 | //I | ||
395 | DoubleFormat df; | ||
396 | |||
397 | df.iWidth = 0; | ||
398 | df.iPrec = _pDFI->iPrec; | ||
399 | df.bExp = _pDFI->bExp; | ||
400 | df.bPrintPlusSign = false; | ||
401 | df.bPrintOne = false; | ||
402 | addDoubleValue(&ostemp, _dblI, &df); | ||
403 | ostemp << std::left << SYMBOL_I; | ||
404 | if (_dblI == 1) | ||
405 | { | ||
406 | addSpaces(&ostemp, 1); | ||
407 | } | ||
408 | 352 | ||
409 | } | 353 | if (ISNAN(_dblR) || !finite(_dblR)) |
354 | { | ||
355 | ostemp << std::left << std::setw(_pDFR->iWidth + 1); | ||
356 | addDoubleValue(&ostemp, _dblR, &df); | ||
410 | } | 357 | } |
411 | else | 358 | else |
412 | { | 359 | { |
413 | //real part | 360 | // following line allows to align sign of imaginary part |
414 | if (_dblI == 0) | 361 | addDoubleValue(&ostemp, _dblR, &df); |
415 | { | 362 | addSpaces(&ostemp, _pDFR->iWidth - ostemp.tellp() + 1); |
416 | //no imaginary part | 363 | } |
417 | 364 | //I | |
418 | //R | 365 | df.iPrec = _pDFI->iPrec; |
419 | DoubleFormat df; | 366 | df.bExp = _pDFI->bExp; |
420 | 367 | df.bPrintPlusSign = true; | |
421 | df.iWidth = 0; | 368 | df.bPrintComplexPlusSpace = true; |
422 | df.iPrec = _pDFR->iPrec; | 369 | df.bPrintOne = false; |
423 | df.bExp = _pDFR->bExp; | 370 | |
424 | addDoubleValue(&ostemp, _dblR, &df); | 371 | addDoubleValue(&ostemp, _dblI, &df); |
425 | } | 372 | ostemp << std::left << SYMBOL_I; |
426 | else | 373 | if (_dblI == 1 && _pDFI->bExp == false) |
427 | { | 374 | { |
428 | //imaginary part | 375 | addSpaces(&ostemp, 2); |
429 | |||
430 | //R | ||
431 | DoubleFormat df; | ||
432 | |||
433 | df.iPrec = _pDFR->iPrec; | ||
434 | df.bExp = _pDFR->bExp; | ||
435 | |||
436 | addDoubleValue(&ostemp, _dblR, &df); | ||
437 | |||
438 | //I | ||
439 | df.iPrec = _pDFI->iPrec; | ||
440 | df.bExp = _pDFI->bExp; | ||
441 | df.bPrintPlusSign = true; | ||
442 | df.bPrintComplexPlusSpace = true; | ||
443 | df.bPrintOne = false; | ||
444 | |||
445 | addDoubleValue(&ostemp, _dblI, &df); | ||
446 | ostemp << std::left << SYMBOL_I; | ||
447 | if (_dblI == 1) | ||
448 | { | ||
449 | addSpaces(&ostemp, 2); | ||
450 | } | ||
451 | } | ||
452 | } | 376 | } |
453 | 377 | ||
454 | configureStream(_postr, _iTotalWidth, 0, ' '); | 378 | configureStream(_postr, _iTotalWidth, 0, ' '); |
@@ -507,8 +431,8 @@ void printDoubleValue(std::wostringstream& ostr, double val) | |||
507 | void printComplexValue(std::wostringstream& ostr, double val_r, double val_i) | 431 | void printComplexValue(std::wostringstream& ostr, double val_r, double val_i) |
508 | { | 432 | { |
509 | DoubleFormat dfR, dfI; | 433 | DoubleFormat dfR, dfI; |
510 | getDoubleFormat(ZeroIsZero(val_r), &dfR); | 434 | int iTotalWidth; |
511 | getDoubleFormat(ZeroIsZero(val_i), &dfI); | 435 | getComplexFormat(ZeroIsZero(val_r), ZeroIsZero(val_i), &iTotalWidth, &dfR, &dfI); |
512 | ostr << SPACE_BETWEEN_TWO_VALUES; | 436 | ostr << SPACE_BETWEEN_TWO_VALUES; |
513 | addDoubleComplexValue(&ostr, ZeroIsZero(val_r), ZeroIsZero(val_i), dfR.iWidth + dfI.iWidth, &dfR, &dfI); | 437 | addDoubleComplexValue(&ostr, ZeroIsZero(val_r), ZeroIsZero(val_i), iTotalWidth, &dfR, &dfI); |
514 | } | 438 | } |
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_15781.dia.ref b/scilab/modules/ast/tests/nonreg_tests/bug_15781.dia.ref new file mode 100644 index 0000000..97eecbe --- /dev/null +++ b/scilab/modules/ast/tests/nonreg_tests/bug_15781.dia.ref | |||
@@ -0,0 +1,172 @@ | |||
1 | // Copyright (C) 2019 - Stéphane MOTTELET | ||
2 | // | ||
3 | // This file is distributed under the same license as the Scilab package. | ||
4 | // ============================================================================= | ||
5 | // | ||
6 | // <-- CLI SHELL MODE --> | ||
7 | // | ||
8 | // <-- Non-regression test for bug 15781 --> | ||
9 | // | ||
10 | // <-- Bugzilla URL --> | ||
11 | // http://bugzilla.scilab.org/15781 | ||
12 | // | ||
13 | // <-- Short Description --> | ||
14 | // display of complex matrix is ugly. | ||
15 | n=4 | ||
16 | n = | ||
17 | 4. | ||
18 | a=testmatrix("magic",4); | ||
19 | for f = ["v","e"] | ||
20 | format(f) | ||
21 | x=complex(cos(a),sin(a)); | ||
22 | x(3,3)=%nan; | ||
23 | x(4,4)=%inf; | ||
24 | x(2,1:2)=1+%i; | ||
25 | x(:,1)=0; | ||
26 | disp(x) | ||
27 | for i=1:n | ||
28 | disp(x(i,:)) | ||
29 | disp(" ") | ||
30 | end | ||
31 | for i=1:n | ||
32 | disp(x(:,i)) | ||
33 | disp(" ") | ||
34 | end | ||
35 | x=x-x; | ||
36 | disp(x) | ||
37 | disp(" ") | ||
38 | acoth(-2:0.5:2).' | ||
39 | end | ||
40 | column 1 to 3 | ||
41 | 0. + 0.i -0.4161468 + 0.9092974i -0.9899925 + 0.14112i | ||
42 | 0. + 0.i 1. + i -0.8390715 - 0.5440211i | ||
43 | 0. + 0.i 0.7539023 + 0.6569866i Nan + 0.i | ||
44 | 0. + 0.i 0.1367372 + 0.9906074i -0.7596879 + 0.6502878i | ||
45 | column 4 | ||
46 | 0.9074468 + 0.420167i | ||
47 | -0.1455 + 0.9893582i | ||
48 | 0.843854 - 0.5365729i | ||
49 | Inf + 0.i | ||
50 | column 1 to 3 | ||
51 | 0. + 0.i -0.4161468 + 0.9092974i -0.9899925 + 0.14112i | ||
52 | column 4 | ||
53 | 0.9074468 + 0.420167i | ||
54 | |||
55 | 0. + 0.i 1. + i -0.8390715 - 0.5440211i -0.1455 + 0.9893582i | ||
56 | |||
57 | column 1 to 3 | ||
58 | 0. + 0.i 0.7539023 + 0.6569866i Nan + 0.i | ||
59 | column 4 | ||
60 | 0.843854 - 0.5365729i | ||
61 | |||
62 | column 1 to 3 | ||
63 | 0. + 0.i 0.1367372 + 0.9906074i -0.7596879 + 0.6502878i | ||
64 | column 4 | ||
65 | Inf + 0.i | ||
66 | |||
67 | 0. + 0.i | ||
68 | 0. + 0.i | ||
69 | 0. + 0.i | ||
70 | 0. + 0.i | ||
71 | |||
72 | -0.4161468 + 0.9092974i | ||
73 | 1. + i | ||
74 | 0.7539023 + 0.6569866i | ||
75 | 0.1367372 + 0.9906074i | ||
76 | |||
77 | -0.9899925 + 0.14112i | ||
78 | -0.8390715 - 0.5440211i | ||
79 | Nan + 0.i | ||
80 | -0.7596879 + 0.6502878i | ||
81 | |||
82 | 0.9074468 + 0.420167i | ||
83 | -0.1455 + 0.9893582i | ||
84 | 0.843854 - 0.5365729i | ||
85 | Inf + 0.i | ||
86 | |||
87 | 0. + 0.i 0. + 0.i 0. + 0.i 0. + 0.i | ||
88 | 0. + 0.i 0. + 0.i 0. + 0.i 0. + 0.i | ||
89 | 0. + 0.i 0. + 0.i Nan + 0.i 0. + 0.i | ||
90 | 0. + 0.i 0. + 0.i 0. + 0.i Nan + 0.i | ||
91 | |||
92 | ans = | ||
93 | -0.5493061 + 0.i | ||
94 | -0.804719 + 0.i | ||
95 | -Inf - 0.7853982i | ||
96 | -0.5493061 - 1.5707963i | ||
97 | 0. - 1.5707963i | ||
98 | 0.5493061 - 1.5707963i | ||
99 | Inf + Nani | ||
100 | 0.804719 + 3.1415927i | ||
101 | 0.5493061 + 3.1415927i | ||
102 | column 1 to 2 | ||
103 | 0.000D+00 + 0.000D+00i -4.161D-01 + 9.093D-01i | ||
104 | 0.000D+00 + 0.000D+00i 1.000D+00 + 1.000D+00i | ||
105 | 0.000D+00 + 0.000D+00i 7.539D-01 + 6.570D-01i | ||
106 | 0.000D+00 + 0.000D+00i 1.367D-01 + 9.906D-01i | ||
107 | column 3 to 4 | ||
108 | -9.900D-01 + 1.411D-01i 9.074D-01 + 4.202D-01i | ||
109 | -8.391D-01 - 5.440D-01i -1.455D-01 + 9.894D-01i | ||
110 | Nan + 0.000D+00i 8.439D-01 - 5.366D-01i | ||
111 | -7.597D-01 + 6.503D-01i Inf + 0.000D+00i | ||
112 | column 1 to 2 | ||
113 | 0.000D+00 + 0.000D+00i -4.161D-01 + 9.093D-01i | ||
114 | column 3 to 4 | ||
115 | -9.900D-01 + 1.411D-01i 9.074D-01 + 4.202D-01i | ||
116 | |||
117 | column 1 to 2 | ||
118 | 0.000D+00 + 0.000D+00i 1.000D+00 + 1.000D+00i | ||
119 | column 3 to 4 | ||
120 | -8.391D-01 - 5.440D-01i -1.455D-01 + 9.894D-01i | ||
121 | |||
122 | column 1 to 3 | ||
123 | 0.000D+00 + 0.000D+00i 7.539D-01 + 6.570D-01i Nan + 0.000D+00i | ||
124 | column 4 | ||
125 | 8.439D-01 - 5.366D-01i | ||
126 | |||
127 | column 1 to 2 | ||
128 | 0.000D+00 + 0.000D+00i 1.367D-01 + 9.906D-01i | ||
129 | column 3 to 4 | ||
130 | -7.597D-01 + 6.503D-01i Inf + 0.000D+00i | ||
131 | |||
132 | 0.000D+00 + 0.000D+00i | ||
133 | 0.000D+00 + 0.000D+00i | ||
134 | 0.000D+00 + 0.000D+00i | ||
135 | 0.000D+00 + 0.000D+00i | ||
136 | |||
137 | -4.161D-01 + 9.093D-01i | ||
138 | 1.000D+00 + 1.000D+00i | ||
139 | 7.539D-01 + 6.570D-01i | ||
140 | 1.367D-01 + 9.906D-01i | ||
141 | |||
142 | -9.900D-01 + 1.411D-01i | ||
143 | -8.391D-01 - 5.440D-01i | ||
144 | Nan + 0.000D+00i | ||
145 | -7.597D-01 + 6.503D-01i | ||
146 | |||
147 | 9.074D-01 + 4.202D-01i | ||
148 | -1.455D-01 + 9.894D-01i | ||
149 | 8.439D-01 - 5.366D-01i | ||
150 | Inf + 0.000D+00i | ||
151 | |||
152 | column 1 to 2 | ||
153 | 0.000D+00 + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
154 | 0.000D+00 + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
155 | 0.000D+00 + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
156 | 0.000D+00 + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
157 | column 3 to 4 | ||
158 | 0.000D+00 + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
159 | 0.000D+00 + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
160 | Nan + 0.000D+00i 0.000D+00 + 0.000D+00i | ||
161 | 0.000D+00 + 0.000D+00i Nan + 0.000D+00i | ||
162 | |||
163 | ans = | ||
164 | -5.493D-01 + 0.000D+00i | ||
165 | -8.047D-01 + 0.000D+00i | ||
166 | -Inf - 7.854D-01i | ||
167 | -5.493D-01 - 1.571D+00i | ||
168 | 0.000D+00 - 1.571D+00i | ||
169 | 5.493D-01 - 1.571D+00i | ||
170 | Inf + Nani | ||
171 | 8.047D-01 + 3.142D+00i | ||
172 | 5.493D-01 + 3.142D+00i | ||
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_15781.tst b/scilab/modules/ast/tests/nonreg_tests/bug_15781.tst new file mode 100644 index 0000000..281972f --- /dev/null +++ b/scilab/modules/ast/tests/nonreg_tests/bug_15781.tst | |||
@@ -0,0 +1,45 @@ | |||
1 | // Copyright (C) 2019 - Stéphane MOTTELET | ||
2 | // | ||
3 | // This file is distributed under the same license as the Scilab package. | ||
4 | // ============================================================================= | ||
5 | // | ||
6 | // <-- CLI SHELL MODE --> | ||
7 | // | ||
8 | // <-- Non-regression test for bug 15781 --> | ||
9 | // | ||
10 | // <-- Bugzilla URL --> | ||
11 | // http://bugzilla.scilab.org/15781 | ||
12 | // | ||
13 | // <-- Short Description --> | ||
14 | // display of complex matrix is ugly. | ||
15 | |||
16 | n=4 | ||
17 | |||
18 | a=testmatrix("magic",4); | ||
19 | |||
20 | for f = ["v","e"] | ||
21 | format(f) | ||
22 | x=complex(cos(a),sin(a)); | ||
23 | x(3,3)=%nan; | ||
24 | x(4,4)=%inf; | ||
25 | x(2,1:2)=1+%i; | ||
26 | x(:,1)=0; | ||
27 | disp(x) | ||
28 | |||
29 | for i=1:n | ||
30 | disp(x(i,:)) | ||
31 | disp(" ") | ||
32 | end | ||
33 | |||
34 | for i=1:n | ||
35 | disp(x(:,i)) | ||
36 | disp(" ") | ||
37 | end | ||
38 | |||
39 | x=x-x; | ||
40 | |||
41 | disp(x) | ||
42 | disp(" ") | ||
43 | |||
44 | acoth(-2:0.5:2).' | ||
45 | end | ||