summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane MOTTELET <stephane.mottelet@utc.fr>2019-10-03 16:58:32 +0200
committerClément DAVID <clement.david@esi-group.com>2019-11-19 22:20:50 +0100
commitd76fdfbfc4c43364f9cb29b44d7a9ff36759d6ae (patch)
tree34dc8605672e4697afe6b3a889db168658734a7b
parent603f3ba125eaae68c7019bf97ad24bc45befe6c8 (diff)
downloadscilab-d76fdfbfc4c43364f9cb29b44d7a9ff36759d6ae.zip
scilab-d76fdfbfc4c43364f9cb29b44d7a9ff36759d6ae.tar.gz
[ast] improved polynomial display with unicode superscripts
Example: --> [(1+%s)^7; 1+%s^12] ans = 1 +7s +21s² +35s³ +35s⁴ +21s⁵ +7s⁶ +s⁷ 1 +s¹² Change-Id: I122941b9e35eb622ad36718e0e9ee311603bb8ae
-rw-r--r--scilab/modules/ast/includes/types/polynom.hxx3
-rw-r--r--scilab/modules/ast/includes/types/singlepoly.hxx6
-rw-r--r--scilab/modules/ast/src/cpp/types/polynom.cpp305
-rw-r--r--scilab/modules/ast/src/cpp/types/singlepoly.cpp68
4 files changed, 75 insertions, 307 deletions
diff --git a/scilab/modules/ast/includes/types/polynom.hxx b/scilab/modules/ast/includes/types/polynom.hxx
index d3653a4..b548b17 100644
--- a/scilab/modules/ast/includes/types/polynom.hxx
+++ b/scilab/modules/ast/includes/types/polynom.hxx
@@ -95,11 +95,8 @@ public :
95 Polynom* set(int _iRows, int _iCols, SinglePoly* _pS) override; 95 Polynom* set(int _iRows, int _iCols, SinglePoly* _pS) override;
96 Polynom* set(SinglePoly** _pS) override; 96 Polynom* set(SinglePoly** _pS) override;
97 97
98 std::wstring getRowString(int* _piDims, int _iDims, bool _bComplex);
99 std::wstring getColString(int* _piDims, int _iDims, bool _bComplex);
100 std::wstring getMatrixString(int* _piDims, int _iDims, bool _bComplex); 98 std::wstring getMatrixString(int* _piDims, int _iDims, bool _bComplex);
101 99
102
103 bool operator==(const InternalType& it) override; 100 bool operator==(const InternalType& it) override;
104 bool operator!=(const InternalType& it) override; 101 bool operator!=(const InternalType& it) override;
105 102
diff --git a/scilab/modules/ast/includes/types/singlepoly.hxx b/scilab/modules/ast/includes/types/singlepoly.hxx
index 1a9a50f..dec00f5 100644
--- a/scilab/modules/ast/includes/types/singlepoly.hxx
+++ b/scilab/modules/ast/includes/types/singlepoly.hxx
@@ -59,8 +59,8 @@ public :
59 bool evaluate(double _dblInR, double _dblInI, double *_pdblOutR, double *_pdblOutI); 59 bool evaluate(double _dblInR, double _dblInI, double *_pdblOutR, double *_pdblOutI);
60 void updateRank(void); 60 void updateRank(void);
61 61
62 void toStringReal(const std::wstring& _szVar, std::list<std::wstring>* _pListExp, std::list<std::wstring>* _pListCoef); 62 void toStringReal(const std::wstring& _szVar, std::list<std::wstring>* _pListCoef);
63 void toStringImg(const std::wstring& _szVar, std::list<std::wstring>* _pListExp, std::list<std::wstring>* _pListCoef); 63 void toStringImg(const std::wstring& _szVar, std::list<std::wstring>* _pListCoef);
64 64
65 bool toString(std::wostringstream& ostr) override; 65 bool toString(std::wostringstream& ostr) override;
66 66
@@ -88,7 +88,7 @@ protected :
88 } 88 }
89 89
90private : 90private :
91 void toStringInternal(double *_pdblVal, const std::wstring& _szVar, std::list<std::wstring>* _pListExp, std::list<std::wstring>* _pListCoef); 91 void toStringInternal(double *_pdblVal, const std::wstring& _szVar, std::list<std::wstring>* _pListCoef);
92 92
93}; 93};
94 94
diff --git a/scilab/modules/ast/src/cpp/types/polynom.cpp b/scilab/modules/ast/src/cpp/types/polynom.cpp
index 535ad80..5ac4d43 100644
--- a/scilab/modules/ast/src/cpp/types/polynom.cpp
+++ b/scilab/modules/ast/src/cpp/types/polynom.cpp
@@ -479,83 +479,23 @@ Polynom* Polynom::setCoef(Double *_pCoef)
479bool Polynom::subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims) 479bool Polynom::subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims)
480{ 480{
481 std::wostringstream osExp; 481 std::wostringstream osExp;
482 std::wostringstream osCoef; 482 std::wostringstream osPoly;
483 483
484 std::list<std::wstring>::const_iterator it_Exp; 484 std::list<std::wstring>::const_iterator it_Exp;
485 std::list<std::wstring>::const_iterator it_Coef; 485 std::list<std::wstring>::const_iterator it_Coef;
486 std::list<std::wstring> listExpR, listCoefR, listExpI, listCoefI; 486 std::list<std::wstring> listExpR, listWstPoly, listExpI, listCoefI;
487 487
488 488 //Matrix
489 if (isScalar()) 489 if (isComplex())
490 {
491 if (isComplex())
492 {
493 ostr << L"Real part" << std::endl << std::endl << std::endl;
494 get(0)->toStringReal(getVariableName(), &listExpR, &listCoefR);
495 for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
496 {
497 ostr << *it_Exp << std::endl << *it_Coef << std::endl;
498 }
499
500 ostr << L"Imaginary part" << std::endl << std::endl << std::endl ;
501 get(0)->toStringImg(getVariableName(), &listExpI, &listCoefI);
502 for (it_Coef = listCoefI.begin(), it_Exp = listExpI.begin() ; it_Coef != listCoefI.end() ; it_Coef++, it_Exp++)
503 {
504 ostr << *it_Exp << std::endl << *it_Coef << std::endl;
505 }
506 }
507 else
508 {
509 get(0)->toStringReal(getVariableName(), &listExpR, &listCoefR);
510
511 for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
512 {
513 ostr << *it_Exp << std::endl << *it_Coef << std::endl;
514 }
515 }
516 }
517 else if (getRows() == 1)
518 {
519 if (isComplex())
520 {
521 ostr << L"Real part" << std::endl << std::endl;
522 ostr << getRowString(_piDims, _iDims, false);
523 ostr << L"Imaginary part" << std::endl << std::endl;
524 ostr << getRowString(_piDims, _iDims, true);
525 }
526 else
527 {
528 ostr << getRowString(_piDims, _iDims, false);
529 }
530 }
531 else if (getCols() == 1)
532 { 490 {
533 if (isComplex()) 491 ostr << L"Real part" << std::endl << std::endl;
534 { 492 ostr << getMatrixString(_piDims, _iDims, false);
535 ostr << L"Real part" << std::endl << std::endl; 493 ostr << L"Imaginary part" << std::endl << std::endl;
536 ostr << getColString(_piDims, _iDims, false); 494 ostr << getMatrixString(_piDims, _iDims, true);
537 ostr << L"Imaginary part" << std::endl << std::endl;
538 ostr << getColString(_piDims, _iDims, true);
539 }
540 else
541 {
542 ostr << getColString(_piDims, _iDims, false);
543 }
544 } 495 }
545 else 496 else
546 { 497 {
547 //Matrix 498 ostr << getMatrixString(_piDims, _iDims, false);
548 if (isComplex())
549 {
550 ostr << L"Real part" << std::endl << std::endl;
551 ostr << getMatrixString(_piDims, _iDims, false);
552 ostr << L"Imaginary part" << std::endl << std::endl;
553 ostr << getMatrixString(_piDims, _iDims, true);
554 }
555 else
556 {
557 ostr << getMatrixString(_piDims, _iDims, false);
558 }
559 } 499 }
560 return true; 500 return true;
561} 501}
@@ -565,20 +505,15 @@ std::wstring Polynom::getMatrixString(int* _piDims, int /*_iDims*/, bool _bCompl
565 int iLineLen = ConfigVariable::getConsoleWidth(); 505 int iLineLen = ConfigVariable::getConsoleWidth();
566 506
567 std::wostringstream ostr; 507 std::wostringstream ostr;
568 std::wostringstream osExp; 508 std::wostringstream osPoly;
569 std::wostringstream osCoef;
570 509
571 std::list<std::wstring>::const_iterator it_Exp;
572 std::list<std::wstring>::const_iterator it_Coef; 510 std::list<std::wstring>::const_iterator it_Coef;
573 std::list<std::wstring> listExpR, listCoefR, listExpI, listCoefI; 511 std::list<std::wstring> listWstPoly;
574 512
575 int iLen = 0; 513 int iLen = 0;
576 int iLastCol = 0; 514 int iLastCol = 0;
577 bool bWordWarp = false; 515 bool bWordWarp = false;
578 516
579 std::wstring szExp, szCoef;
580
581
582 int *piMaxLen = new int[abs(getCols())]; 517 int *piMaxLen = new int[abs(getCols())];
583 memset(piMaxLen, 0x00, sizeof(int) * abs(getCols())); 518 memset(piMaxLen, 0x00, sizeof(int) * abs(getCols()));
584 519
@@ -593,34 +528,19 @@ std::wstring Polynom::getMatrixString(int* _piDims, int /*_iDims*/, bool _bCompl
593 int iPos = getIndex(_piDims); 528 int iPos = getIndex(_piDims);
594 if (_bComplex) 529 if (_bComplex)
595 { 530 {
596 get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR); 531 get(iPos)->toStringImg(getVariableName(), &listWstPoly);
597 } 532 }
598 else 533 else
599 { 534 {
600 get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR); 535 get(iPos)->toStringReal(getVariableName(), &listWstPoly);
601 } 536 }
602 537
603 if (listExpR.size() > 1) 538 for (auto it : listWstPoly)
604 { 539 {
605 for (it_Exp = listExpR.begin() ; it_Exp != listExpR.end() ; it_Exp++) 540 iLength += static_cast<int>(it.size());
606 {
607 iLength += static_cast<int>((*it_Exp).size());
608 }
609 }
610 else
611 {
612 if (listExpR.front().size() != 0)
613 {
614 iLength = static_cast<int>(listExpR.front().size());
615 }
616 else
617 {
618 iLength = static_cast<int>(listCoefR.front().size());
619 }
620 } 541 }
621 piMaxLen[iCols1] = std::min(std::max(piMaxLen[iCols1], iLength), iLineLen); 542 piMaxLen[iCols1] = std::min(std::max(piMaxLen[iCols1], iLength), iLineLen);
622 listExpR.clear(); 543 listWstPoly.clear();
623 listCoefR.clear();
624 } 544 }
625 545
626 //We know the length of the column 546 //We know the length of the column
@@ -640,51 +560,39 @@ std::wstring Polynom::getMatrixString(int* _piDims, int /*_iDims*/, bool _bCompl
640 int iPos = getIndex(_piDims); 560 int iPos = getIndex(_piDims);
641 if (_bComplex) 561 if (_bComplex)
642 { 562 {
643 get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR); 563 get(iPos)->toStringImg(getVariableName(), &listWstPoly);
644 } 564 }
645 else 565 else
646 { 566 {
647 get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR); 567 get(iPos)->toStringReal(getVariableName(), &listWstPoly);
648 } 568 }
649 569
650 if (listCoefR.size() > 1) 570 if (listWstPoly.size() > 1)
651 { 571 {
652 for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++) 572 for (auto it : listWstPoly)
653 { 573 {
654 osExp << *it_Exp; 574 osPoly << it << std::endl;
655 addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Exp).size()));
656 osExp << std::endl;
657 osExp << *it_Coef;
658 addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Coef).size()));
659 osExp << std::endl;
660 bMultiLine = true; 575 bMultiLine = true;
661 } 576 }
662 } 577 }
663 else 578 else
664 { 579 {
665 580 osPoly << listWstPoly.front();
666 osExp << listExpR.front(); 581 addSpaces(&osPoly, piMaxLen[iCols2] - static_cast<int>(listWstPoly.front().size()));
667 addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>(listExpR.front().size()));
668 osCoef << listCoefR.front();
669 addSpaces(&osCoef, piMaxLen[iCols2] - static_cast<int>(listCoefR.front().size()));
670 bMultiLine = false; 582 bMultiLine = false;
671 } 583 }
672 listExpR.clear(); 584 listWstPoly.clear();
673 listCoefR.clear();
674 } 585 }
675 586
676 if (bMultiLine == false) 587 if (bMultiLine == false)
677 { 588 {
678 osExp << std::endl; 589 osPoly << std::endl;
679 osCoef << std::endl;
680 } 590 }
681 ostemp << osExp.str(); 591 ostemp << osPoly.str() << std::endl;
682 ostemp << osCoef.str() << std::endl; 592 osPoly.str(L"");
683 osExp.str(L"");
684 osCoef.str(L"");
685 593
686 } 594 }
687 iLen = piMaxLen[iCols1]; 595 iLen = piMaxLen[iCols1];
688 596
689 //write "column x to y" 597 //write "column x to y"
690 addColumnString(ostr, iLastCol + 1, iCols1); 598 addColumnString(ostr, iLastCol + 1, iCols1);
@@ -714,176 +622,41 @@ std::wstring Polynom::getMatrixString(int* _piDims, int /*_iDims*/, bool _bCompl
714 int iPos = getIndex(_piDims); 622 int iPos = getIndex(_piDims);
715 if (_bComplex) 623 if (_bComplex)
716 { 624 {
717 get(iPos)->toStringImg( getVariableName(), &listExpR, &listCoefR); 625 get(iPos)->toStringImg(getVariableName(), &listWstPoly);
718 } 626 }
719 else 627 else
720 { 628 {
721 get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR); 629 get(iPos)->toStringReal(getVariableName(), &listWstPoly);
722 } 630 }
723 631
724 if (listCoefR.size() > 1) 632 if (listWstPoly.size() > 1)
725 { 633 {
726 for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++) 634 for (auto it : listWstPoly)
727 { 635 {
728 //normally useless ... 636 osPoly << it << std::endl;
729 osExp << *it_Exp;
730 addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Exp).size()));
731 osExp << std::endl;
732
733 osExp << *it_Coef;
734 addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Coef).size()));
735 osExp << std::endl;
736 } 637 }
737 } 638 }
738 else 639 else
739 { 640 {
740 if (listExpR.front().size() != 0) 641 osPoly << listWstPoly.front();
741 { 642 addSpaces(&osPoly, piMaxLen[iCols2] - static_cast<int>(listWstPoly.front().size()));
742 osExp << listExpR.front();
743 }
744
745 addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>(listExpR.front().size()));
746 osCoef << listCoefR.front();
747 addSpaces(&osCoef, piMaxLen[iCols2] - static_cast<int>(listCoefR.front().size()));
748 } 643 }
749 listExpR.clear(); 644 listWstPoly.clear();
750 listCoefR.clear();
751 } 645 }
752 646
753 if (osExp.str().size() != 0) 647 osPoly << std::endl;
754 {
755 osExp << std::endl;
756 }
757 osCoef << std::endl;
758 if (isIdentity()) 648 if (isIdentity())
759 { 649 {
760 ostr << L"eye *" << std::endl << std::endl; 650 ostr << L"eye *" << std::endl << std::endl;
761 } 651 }
762 ostr << osExp.str(); 652 ostr << osPoly.str() << std::endl;
763 ostr << osCoef.str() << std::endl; 653 osPoly.str(L"");
764 osExp.str(L"");
765 osCoef.str(L"");
766 } 654 }
767 655
768 delete[] piMaxLen; 656 delete[] piMaxLen;
769 return ostr.str(); 657 return ostr.str();
770} 658}
771 659
772std::wstring Polynom::getRowString(int* _piDims, int /*_iDims*/, bool _bComplex)
773{
774 int iLineLen = ConfigVariable::getConsoleWidth();
775
776 int iLen = 0;
777 int iLastFlush = 0;
778
779 std::wostringstream ostr;
780 std::wostringstream osExp;
781 std::wostringstream osCoef;
782
783 std::list<std::wstring>::const_iterator it_Exp;
784 std::list<std::wstring>::const_iterator it_Coef;
785 std::list<std::wstring> listExpR, listCoefR, listExpI, listCoefI;
786
787 for (int i = 0 ; i < getCols() ; i++)
788 {
789 std::wstring szExp, szCoef;
790
791 _piDims[1] = 0;
792 _piDims[0] = i;
793 int iPos = getIndex(_piDims);
794 if (_bComplex)
795 {
796 get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR);
797 }
798 else
799 {
800 get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
801 }
802
803 if (iLen != 0 && static_cast<int>(listExpR.front().size()) + iLen >= iLineLen - 1)
804 {
805 //flush strean
806 addColumnString(ostr, iLastFlush + 1, i);
807 iLastFlush = i;
808 iLen = 0;
809 ostr << osExp.str() << std::endl;
810 ostr << osCoef.str() << std::endl;
811 osExp.str(L" ");
812 osCoef.str(L" ");
813 }
814
815 if (listCoefR.size() > 1)
816 {
817 for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
818 {
819 osExp << *it_Exp << std::endl << *it_Coef << std::endl;
820 }
821 }
822 else
823 {
824 osExp << listExpR.front();
825 osCoef << listCoefR.front();
826 }
827
828 if (osExp.str().size() != 0)
829 {
830 iLen = static_cast<int>(osExp.str().size());
831 }
832 else
833 {
834 iLen = static_cast<int>(osCoef.str().size());
835 }
836
837 listCoefR.clear();
838 listExpR.clear();
839 }
840
841 if (iLastFlush != 0)
842 {
843 //last line of a multiline output
844 addColumnString(ostr, iLastFlush + 1, getSize());
845 }
846 ostr << osExp.str() << std::endl;
847 ostr << osCoef.str() << std::endl;
848 return ostr.str();
849}
850
851std::wstring Polynom::getColString(int* _piDims, int /*_iDims*/, bool _bComplex)
852{
853 std::wostringstream ostr;
854 std::wostringstream osExp;
855 std::wostringstream osCoef;
856
857 std::list<std::wstring>::const_iterator it_Exp;
858 std::list<std::wstring>::const_iterator it_Coef;
859 std::list<std::wstring> listExpR, listCoefR, listExpI, listCoefI;
860
861 for (int i = 0 ; i < getRows() ; i++)
862 {
863 std::wstring szExp, szCoef;
864
865 _piDims[0] = i;
866 _piDims[1] = 0;
867 int iPos = getIndex(_piDims);
868 if (_bComplex)
869 {
870 get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR);
871 }
872 else
873 {
874 get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
875 }
876
877 for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
878 {
879 ostr << *it_Exp << std::endl << *it_Coef << std::endl;
880 }
881 ostr << std::endl;
882 listCoefR.clear();
883 listExpR.clear();
884 }
885 return ostr.str();
886}
887 660
888Double* Polynom::extractCoef(int _iRank) 661Double* Polynom::extractCoef(int _iRank)
889{ 662{
diff --git a/scilab/modules/ast/src/cpp/types/singlepoly.cpp b/scilab/modules/ast/src/cpp/types/singlepoly.cpp
index 6361219..04a15cf 100644
--- a/scilab/modules/ast/src/cpp/types/singlepoly.cpp
+++ b/scilab/modules/ast/src/cpp/types/singlepoly.cpp
@@ -334,21 +334,20 @@ bool SinglePoly::toString(std::wostringstream& ostr)
334 return true; 334 return true;
335} 335}
336 336
337void SinglePoly::toStringReal(const std::wstring& _szVar, std::list<std::wstring>* _pListExp, std::list<std::wstring>* _pListCoef) 337void SinglePoly::toStringReal(const std::wstring& _szVar, std::list<std::wstring>* _pListWstPoly)
338{ 338{
339 toStringInternal(m_pRealData, _szVar, _pListExp, _pListCoef); 339 toStringInternal(m_pRealData, _szVar, _pListWstPoly);
340} 340}
341 341
342void SinglePoly::toStringImg(const std::wstring& _szVar, std::list<std::wstring>* _pListExp, std::list<std::wstring>* _pListCoef) 342void SinglePoly::toStringImg(const std::wstring& _szVar, std::list<std::wstring>* _pListWstPoly)
343{ 343{
344 if (isComplex() == false) 344 if (isComplex() == false)
345 { 345 {
346 _pListExp->clear(); 346 _pListWstPoly->clear();
347 _pListCoef->clear();
348 return; 347 return;
349 } 348 }
350 349
351 toStringInternal(m_pImgData, _szVar, _pListExp, _pListCoef); 350 toStringInternal(m_pImgData, _szVar, _pListWstPoly);
352} 351}
353 352
354bool SinglePoly::subMatrixToString(std::wostringstream& /*ostr*/, int* /*_piDims*/, int /*_iDims*/) 353bool SinglePoly::subMatrixToString(std::wostringstream& /*ostr*/, int* /*_piDims*/, int /*_iDims*/)
@@ -356,16 +355,18 @@ bool SinglePoly::subMatrixToString(std::wostringstream& /*ostr*/, int* /*_piDims
356 return false; 355 return false;
357} 356}
358 357
359void SinglePoly::toStringInternal(double *_pdblVal, const std::wstring& _szVar, std::list<std::wstring>* _pListExp, std::list<std::wstring>* _pListCoef) 358void SinglePoly::toStringInternal(double *_pdblVal, const std::wstring& _szVar, std::list<std::wstring>* _pListWstPoly)
360{ 359{
361 int iLineLen = ConfigVariable::getConsoleWidth(); 360 int iLineLen = ConfigVariable::getConsoleWidth();
362 361
362 std::wstring strExponentDigits (L"\u2070\u00B9\u00B2\u00B3\u2074\u2075\u2076\u2077\u2078\u2079");
363 std::vector<int> iExponentsDigits = {0};
363 std::wostringstream ostemp; 364 std::wostringstream ostemp;
364 std::wostringstream ostemp2; 365 bool bFirst = true;
365 366
366 ostemp << L" "; 367 ostemp << L" ";
367 ostemp2 << L" ";
368 368
369 int k;
369 int iLen = 0; 370 int iLen = 0;
370 int iLastFlush = 2; 371 int iLastFlush = 2;
371 for (int i = 0 ; i < m_iSize ; i++) 372 for (int i = 0 ; i < m_iSize ; i++)
@@ -378,45 +379,50 @@ void SinglePoly::toStringInternal(double *_pdblVal, const std::wstring& _szVar,
378 if (iLen + df.iWidth + df.iSignLen >= iLineLen - 1) 379 if (iLen + df.iWidth + df.iSignLen >= iLineLen - 1)
379 { 380 {
380 iLastFlush = i; 381 iLastFlush = i;
381 _pListExp->push_back(ostemp2.str()); 382 _pListWstPoly->push_back(ostemp.str());
382 ostemp2.str(L""); //reset stream
383 addSpaces(&ostemp2, 11); //take from scilab ... why not ...
384
385 _pListCoef->push_back(ostemp.str());
386 ostemp.str(L""); //reset stream 383 ostemp.str(L""); //reset stream
387 addSpaces(&ostemp, 11); //take from scilab ... why not ... 384 addSpaces(&ostemp, 1); //take from scilab ... why not ...
388 } 385 }
389 386
390 bool bFirst = ostemp.str().size() == 1;
391
392 // In scientific notation case bExp == true, so we have to print point (2.000D+10s) 387 // In scientific notation case bExp == true, so we have to print point (2.000D+10s)
393 // In other case don't print point (2s) 388 // In other case don't print point (2s)
394 df.bPrintPoint = df.bExp; 389 df.bPrintPoint = df.bExp;
395 df.bPrintPlusSign = bFirst == false; 390 df.bPrintPlusSign = bFirst == false;
396 df.bPrintOne = i == 0; 391 df.bPrintOne = i == 0;
392 bFirst = false;
397 addDoubleValue(&ostemp, _pdblVal[i], &df); 393 addDoubleValue(&ostemp, _pdblVal[i], &df);
398 394
399 if (i == 0) 395 if (i == 0)
400 { 396 {
401 iLen = static_cast<int>(ostemp.str().size()); 397 iLen = static_cast<int>(ostemp.str().size());
402 } 398 }
403 else if (i == 1) 399 else if (i == 1)
404 { 400 {
405 // add polynom name 401 // add polynomial variable
406 ostemp << _szVar; 402 ostemp << _szVar;
407 iLen = static_cast<int>(ostemp.str().size()); 403 iLen = static_cast<int>(ostemp.str().size());
408 } 404 }
409 else 405 else
410 { 406 {
411 // add polynom name and exponent 407 // add polynomial variable and exponent
412 ostemp << _szVar; 408 ostemp << _szVar;
413 iLen = static_cast<int>(ostemp.str().size()); 409 for (auto it = iExponentsDigits.rbegin(); it != iExponentsDigits.rend(); ++it)
414 addSpaces(&ostemp2, iLen - static_cast<int>(ostemp2.str().size())); 410 {
415 ostemp2 << i; 411 ostemp << strExponentDigits[*it];
416 int iSize = static_cast<int>(ostemp2.str().size()) - iLen; 412 }
417 addSpaces(&ostemp, iSize); 413 iLen = static_cast<int>(ostemp.str().size());
418 } 414 }
419 } 415 }
416
417 for (k=0; k < iExponentsDigits.size() && iExponentsDigits[k] == 9; k++)
418 {
419 iExponentsDigits[k] = 0;
420 }
421 if (k == iExponentsDigits.size())
422 {
423 iExponentsDigits.push_back(0);
424 }
425 iExponentsDigits[k]++;
420 } 426 }
421 427
422 if (iLastFlush != 0) 428 if (iLastFlush != 0)
@@ -424,17 +430,9 @@ void SinglePoly::toStringInternal(double *_pdblVal, const std::wstring& _szVar,
424 if (ostemp.str() == L" ") 430 if (ostemp.str() == L" ")
425 { 431 {
426 ostemp << L" 0"; 432 ostemp << L" 0";
427 addSpaces(&ostemp2, static_cast<int>(ostemp.str().size()));
428 }
429
430 if (ostemp2.str() == L" ")
431 {
432 // -1 because ostemp2 have already a space
433 addSpaces(&ostemp2, static_cast<int>(ostemp.str().size()) - 1);
434 } 433 }
435 434
436 _pListExp->push_back(ostemp2.str()); 435 _pListWstPoly->push_back(ostemp.str());
437 _pListCoef->push_back(ostemp.str());
438 } 436 }
439 437
440 return; 438 return;