From 73315c1667749b7e630d981b95ae9121c1198e03 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Mottelet?= Date: Wed, 28 Nov 2018 17:51:54 +0100 Subject: [PATCH] * Bug 15886 fixed: display of polynomials repaired http://bugzilla.scilab.org/show_bug.cgi?id=15886 also fixes regression on implicit polynomial display Change-Id: I0a980e3cb49e0de9519aa72b78ad9af2dc09a875 --- scilab/CHANGES.md | 5 +- .../modules/ast/src/cpp/types/tostring_common.cpp | 50 ++++++++++---------- .../modules/ast/tests/nonreg_tests/bug_15886.tst | 19 ++++++++ 3 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 scilab/modules/ast/tests/nonreg_tests/bug_15886.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index eee5db8..6361ae1 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -408,7 +408,7 @@ Known issues ### Bugs fixed in 6.0.2: -* [#2247](http://bugzilla.scilab.org/show_bug.cgi?id=2247): The axes_properties page did not show how to yield vertical x-tick labels. `.grid_style`, `.grid_thickness`, and `.axes_bounds` inside a uicontrol frame were not documented. +* [#2247](http://bugzilla.scilab.org/show_bug.cgi?id=2247): The axes_properties page did not show how to yield vertical x-tick labels. `.grid_style`, `.grid_thickness`, and `.axes_bounds` inside a uicontrol frame were not documented. * [#2464](http://bugzilla.scilab.org/show_bug.cgi?id=2464): `null()` was poorly documented. * [#4050](http://bugzilla.scilab.org/show_bug.cgi?id=4050): `ged()` did not support graphical texts with a font size > 5. * [#4953](http://bugzilla.scilab.org/show_bug.cgi?id=4953): The `clean` function does not work when the matrix contains %inf. @@ -652,10 +652,11 @@ Known issues * [#15818](http://bugzilla.scilab.org/show_bug.cgi?id=15818): `polarplot()` example could not be subplotted. `polarplot`'s demo did not display 'View code' and too often prompted the user. * [#15827](http://bugzilla.scilab.org/show_bug.cgi?id=15828): After `bode(..'rad')`, abscissae were titled 'Fréquence' instead of 'Pulsation' in french, and datatips still shew 'Hz' instead of 'rad/s'. * [#15847](http://bugzilla.scilab.org/show_bug.cgi?id=15847): Scilab crashed at startup. -* [#15850](http://bugzilla.scilab.org/show_bug.cgi?id=15850): Adding a space after a string increases its size. +* [#15850](http://bugzilla.scilab.org/show_bug.cgi?id=15850): Adding a space after a string increases its size. * [#15854](http://bugzilla.scilab.org/show_bug.cgi?id=15854): `horner(1:$,4)` yielded an error. Extractions from `cblock` tables were impacted. * [#15878](http://bugzilla.scilab.org/show_bug.cgi?id=15878): `sgrid` and `evans` were broken. * [#15880](http://bugzilla.scilab.org/show_bug.cgi?id=15880): `sgrid` needed some improvements: Labeling was sometimes ambiguous ; large circles were not labeled ; data_bounds did not always take the input wn into account ; named and #RRGGBB colors specifications could not be used. `evans` needed some improvements: the block of legends hid data ; asymptotes were too visible. +* [#15886](http://bugzilla.scilab.org/show_bug.cgi?id=15886): Display of polynomials was broken. * [#15890](http://bugzilla.scilab.org/show_bug.cgi?id=15890): `evstr` sometimes yielded some `+[]` warnings. * [#15907](http://bugzilla.scilab.org/show_bug.cgi?id=15907): `filter` was corrupting its input state array * [#15920](http://bugzilla.scilab.org/show_bug.cgi?id=15920): genlib() did not regenerate a missing .bin if the .sci was unchanged (Scilab 6 regression) diff --git a/scilab/modules/ast/src/cpp/types/tostring_common.cpp b/scilab/modules/ast/src/cpp/types/tostring_common.cpp index 78f8ae5..16ced09 100644 --- a/scilab/modules/ast/src/cpp/types/tostring_common.cpp +++ b/scilab/modules/ast/src/cpp/types/tostring_common.cpp @@ -275,13 +275,13 @@ void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * else if (_pDF->bExp) { // Prints the exponent part 1.543D+03 for example - int decpt = 0; - int sign = 0; - char *rve = nullptr; - char *dtoa_str = dtoa(fabs(_dblVal), 2, _pDF->iPrec + 1, &decpt, &sign, &rve); + int iDecpt = 0; + int iSign = 0; + char *pRve = nullptr; + char *pDtoaStr = dtoa(fabs(_dblVal), 2, _pDF->iPrec + 1, &iDecpt, &iSign, &pRve); - std::string str(dtoa_str); - freedtoa(dtoa_str); + std::string str(pDtoaStr); + freedtoa(pDtoaStr); // in format("e") omiting the decimal point has a sense // only if fabs(_dblVal) is an integer in {1...9} @@ -292,40 +292,42 @@ void addDoubleValue(std::wostringstream * _postr, double _dblVal, DoubleFormat * str.insert(1, "."); } - wchar_t* tmp = to_wide_string(str.data()); - os_swprintf(pwstOutput, 32, L"%ls%lsD%+.02d", pwstSign, tmp, decpt - 1); - FREE(tmp); + wchar_t* pwstData = to_wide_string(str.data()); + os_swprintf(pwstOutput, 32, L"%ls%lsD%+.02d", pwstSign, pwstData, iDecpt - 1); + FREE(pwstData); } else if ((_pDF->bPrintOne == true) || (isEqual(fabs(_dblVal), 1)) == false) { //do not print if _bPrintOne == false && _dblVal == 1 - int decpt = 0; - int sign = 0; - char *rve = nullptr; - char *dtoa_str = dtoa(fabs(_dblVal), 2, std::floor(log10(fabs(_dblVal))) + _pDF->iPrec + 1, &decpt, &sign, &rve); + int iDecpt = 0; + int iSign = 0; + int iWidth = _pDF->iWidth; + char *pRve = nullptr; + char *pDtoaStr = dtoa(fabs(_dblVal), 2, std::floor(log10(fabs(_dblVal))) + _pDF->iPrec + 1, &iDecpt, &iSign, &pRve); - std::string str(dtoa_str); - freedtoa(dtoa_str); + std::string str(pDtoaStr); + freedtoa(pDtoaStr); /* add leading 0.000..., if applicable */ - if (decpt <= 0) + if (iDecpt <= 0) { - str.insert(str.begin(), 1 - decpt, '0'); + str.insert(str.begin(), 1 - iDecpt, '0'); str.insert(1, "."); } - else if (_pDF->bPrintPoint || decpt < str.length()) + else if (_pDF->bPrintPoint || iDecpt < str.length()) { - str.append(std::max(0, (int)(decpt - str.length())), '0'); - str.insert(decpt, "."); + str.append(std::max(0, (int)(iDecpt - str.length())), '0'); + str.insert(iDecpt, "."); } else { - str.append(std::max(0, (int)(decpt - str.length())), '0'); + str.append(std::max(0, (int)(iDecpt - str.length())), '0'); + iWidth--; } - wchar_t* tmp = to_wide_string(str.data()); - os_swprintf(pwstOutput, 32, L"%ls%-*ls", pwstSign,_pDF->iWidth-1,tmp); - FREE(tmp); + wchar_t* pwstData = to_wide_string(str.data()); + os_swprintf(pwstOutput, 32, L"%ls%-*ls", pwstSign, iWidth-1, pwstData); + FREE(pwstData); } else if (wcslen(pwstSign) != 0) { diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_15886.tst b/scilab/modules/ast/tests/nonreg_tests/bug_15886.tst new file mode 100644 index 0000000..c1b0a89 --- /dev/null +++ b/scilab/modules/ast/tests/nonreg_tests/bug_15886.tst @@ -0,0 +1,19 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2018 - Stéphane MOTTELET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> +// +// <-- Non-regression test for bug 15886 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/15886 +// +// <-- Short Description --> +// display of polynomials is broken + +assert_checkequal(string((1-%s)^3),[" 2 3";"1 - 3s + 3s - s"]); \ No newline at end of file -- 1.7.9.5