rpms/kdeutils/devel kdeutils-3.5.0-kcalc.patch, NONE, 1.1 kdeutils.spec, 1.50, 1.51
fedora-cvs-commits at redhat.com
fedora-cvs-commits at redhat.com
Mon Jan 16 18:58:11 UTC 2006
- Previous message (by thread): rpms/lm_sensors/devel lm_sensors.init, 1.5, 1.6 lm_sensors.spec, 1.30, 1.31
- Next message (by thread): rpms/kudzu/devel .cvsignore, 1.96, 1.97 kudzu.spec, 1.109, 1.110 sources, 1.107, 1.108
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: than
Update of /cvs/dist/rpms/kdeutils/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv2699
Modified Files:
kdeutils.spec
Added Files:
kdeutils-3.5.0-kcalc.patch
Log Message:
apply patch to fix #176463
kdeutils-3.5.0-kcalc.patch:
kcalc_core.cpp | 2
kcalcdisplay.cpp | 17 +---
knumber/knumber.cpp | 192 +++++++++++++++++++++++++++++++++++++++--------
knumber/knumber.h | 28 +++---
knumber/knumber_priv.cpp | 35 +++++---
knumber/knumber_priv.h | 10 +-
stats.cpp | 16 +--
7 files changed, 218 insertions(+), 82 deletions(-)
--- NEW FILE kdeutils-3.5.0-kcalc.patch ---
diff -Nur kdeutils-3.5.0.orig/kcalc/kcalc_core.cpp kdeutils-3.5.0/kcalc/kcalc_core.cpp
--- kdeutils-3.5.0.orig/kcalc/kcalc_core.cpp 2005-10-10 16:59:12.000000000 +0200
+++ kdeutils-3.5.0/kcalc/kcalc_core.cpp 2006-01-16 19:41:11.000000000 +0100
@@ -770,7 +770,7 @@
void CalcEngine::TangensHyp(KNumber input)
{
- CALCAMNT tmp_num = input.toQString().toDouble();
+ CALCAMNT tmp_num = static_cast<double>(input);
_last_number = KNumber(double(TANH(tmp_num)));
}
diff -Nur kdeutils-3.5.0.orig/kcalc/kcalcdisplay.cpp kdeutils-3.5.0/kcalc/kcalcdisplay.cpp
--- kdeutils-3.5.0.orig/kcalc/kcalcdisplay.cpp 2005-11-19 11:03:43.000000000 +0100
+++ kdeutils-3.5.0/kcalc/kcalcdisplay.cpp 2006-01-16 19:41:11.000000000 +0100
@@ -119,7 +119,11 @@
void KCalcDisplay::slotCopy(void)
{
- QString txt = _display_amount.toQString();
+ QString txt;
+ if (_num_base != NB_DECIMAL)
+ txt = QLabel::text();
+ else
+ txt = _display_amount.toQString();
if (_num_base == NB_HEX)
txt.prepend( "0x" );
(QApplication::clipboard())->setText(txt, QClipboard::Clipboard);
@@ -275,15 +279,10 @@
}
else // _num_base == NB_DECIMAL
{
- // We need to use QCString here since it uses the systems native ::sprintf()
- // implementation which is more flexible than QString's.
- _display_amount = new_amount;
+ _display_amount = new_amount;
-
- display_str = _display_amount.toQString(QString().setNum(KCalcSettings::precision()));
+ display_str = _display_amount.toQString(KCalcSettings::precision(), _fixed_precision);
#if 0
- if (_fixed_precision != -1 && _display_amount <= 1.0e+16)
- display_str = QCString().sprintf(PRINT_FLOAT, _fixed_precision, _display_amount);
else if (_display_amount > 1.0e+16)
display_str = QCString().sprintf(PRINT_LONG_BIG, _precision + 1, _display_amount);
else
@@ -317,7 +316,7 @@
{
if (_num_base != NB_DECIMAL)
return QLabel::text();
- QString display_str = _display_amount.toQString(QString().setNum(KCalcSettings::precision()));
+ QString display_str = _display_amount.toQString(KCalcSettings::precision());
return display_str;
// return QCString().sprintf(PRINT_LONG_BIG, 40, _display_amount);
diff -Nur kdeutils-3.5.0.orig/kcalc/knumber/knumber.cpp kdeutils-3.5.0/kcalc/knumber/knumber.cpp
--- kdeutils-3.5.0.orig/kcalc/knumber/knumber.cpp 2005-10-10 16:59:12.000000000 +0200
+++ kdeutils-3.5.0/kcalc/knumber/knumber.cpp 2006-01-16 19:41:47.000000000 +0100
@@ -207,56 +207,188 @@
return *this;
}
-QString const KNumber::toQString(QString const & prec) const
+// increase the digit at 'position' by one
+static void _inc_by_one(QString &str, int position)
+{
+ for (int i = position; i >= 0; i--)
+ {
+ char last_char = str[i].latin1();
+ switch(last_char)
+ {
+ case '0':
+ str[i] = '1';
+ break;
+ case '1':
+ str[i] = '2';
+ break;
+ case '2':
+ str[i] = '3';
+ break;
+ case '3':
+ str[i] = '4';
+ break;
+ case '4':
+ str[i] = '5';
+ break;
+ case '5':
+ str[i] = '6';
+ break;
+ case '6':
+ str[i] = '7';
+ break;
+ case '7':
+ str[i] = '8';
+ break;
+ case '8':
+ str[i] = '9';
+ break;
+ case '9':
+ str[i] = '0';
+ if (i == 0) str.prepend('1');
+ continue;
+ case '.':
+ continue;
+ }
+ break;
+ }
+}
+
+// Cut off if more digits in fractional part than 'precision'
+static void _round(QString &str, int precision)
+{
+ int decimalSymbolPos = str.find('.');
+
+ if (decimalSymbolPos == -1)
+ if (precision == 0) return;
+ else if (precision > 0) // add dot if missing (and needed)
+ {
+ str.append('.');
+ decimalSymbolPos = str.length() - 1;
+ }
+
+ // fill up with more than enough zeroes (in case fractional part too short)
+ str.append(QString().fill('0', precision));
+
+ // Now decide whether to round up or down
+ char last_char = str[decimalSymbolPos + precision + 1].latin1();
+ switch (last_char)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ // nothing to do, rounding down
+ break;
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ // rounding up
+ _inc_by_one(str, decimalSymbolPos + precision);
+ break;
+ default:
+ break;
+ }
+
+ decimalSymbolPos = str.find('.');
+ str.truncate(decimalSymbolPos + precision + 1);
+
+ // if precision == 0 delete also '.'
+ if (precision == 0) str = str.section('.', 0, 0);
+}
+
+static QString roundNumber(const QString &numStr, int precision)
+{
+ QString tmpString = numStr;
+ if (precision < 0 ||
+ ! QRegExp("^[+-]?\\d+(\\.\\d+)*(e[+-]?\\d+)?$").exactMatch(tmpString))
+ return numStr;
+
+
+ // Skip the sign (for now)
+ bool neg = (tmpString[0] == '-');
+ if (neg || tmpString[0] == '+') tmpString.remove(0, 1);
+
+
+ // Split off exponential part (including 'e'-symbol)
+ QString mantString = tmpString.section('e', 0, 0,
+ QString::SectionCaseInsensitiveSeps);
+ QString expString = tmpString.section('e', 1, 1,
+ QString::SectionCaseInsensitiveSeps |
+ QString::SectionIncludeLeadingSep);
+ if (expString.length() == 1) expString = QString();
+
+
+ _round(mantString, precision);
+
+ if(neg) mantString.prepend('-');
+
+ return mantString + expString;
+}
+
+
+QString const KNumber::toQString(int width, int prec) const
{
QString tmp_str;
+
+ if (*this == Zero) // important to avoid infinite loops below
+ return "0";
switch (type()) {
case IntegerType:
- tmp_str = QString(_num->ascii(prec));
- if (QRegExp("^\\d+$").exactMatch(prec)) {
- int int_num = prec.toInt();
- if (int_num < tmp_str.length()) {
- bool tmp_bool = _fraction_input; // stupid work-around
- _fraction_input = false;
- tmp_str = (KNumber("1.0")*(*this)).toQString(prec);
- _fraction_input = tmp_bool;
- }
- }
+ if (width > 0) { //result needs to be cut-off
+ bool tmp_bool = _fraction_input; // stupid work-around
+ _fraction_input = false;
+ tmp_str = (KNumber("1.0")*(*this)).toQString(width, -1);
+ _fraction_input = tmp_bool;
+ } else
+ tmp_str = QString(_num->ascii());
break;
case FractionType:
if (_float_output) {
bool tmp_bool = _fraction_input; // stupid work-around
_fraction_input = false;
- tmp_str = QString((KNumber("1.0")*(*this))._num->ascii());
+ tmp_str = (KNumber("1.0")*(*this)).toQString(width, -1);
_fraction_input = tmp_bool;
- }
- else if(_splitoffinteger_output) {
- // split off integer part
- KNumber int_part = this->integerPart();
- if (int_part == Zero)
+ } else { // _float_output == false
+ if(_splitoffinteger_output) {
+ // split off integer part
+ KNumber int_part = this->integerPart();
+ if (int_part == Zero)
+ tmp_str = QString(_num->ascii());
+ else if (int_part < Zero)
+ tmp_str = int_part.toQString() + " " + (int_part - *this)._num->ascii();
+ else
+ tmp_str = int_part.toQString() + " " + (*this - int_part)._num->ascii();
+ } else
tmp_str = QString(_num->ascii());
- else if (int_part < Zero)
- tmp_str = int_part.toQString() + " " + (int_part - *this)._num->ascii();
- else
- tmp_str = int_part.toQString() + " " + (*this - int_part)._num->ascii();
- } else
- tmp_str = QString(_num->ascii());
- if (QRegExp("^\\d+$").exactMatch(prec)) {
- int int_num = prec.toInt();
- if (int_num < tmp_str.length()) {
+ if (width > 0 && tmp_str.length() > width) {
+ //result needs to be cut-off
bool tmp_bool = _fraction_input; // stupid work-around
_fraction_input = false;
- tmp_str = (KNumber("1.0")*(*this)).toQString(prec);
+ tmp_str = (KNumber("1.0")*(*this)).toQString(width, -1);
_fraction_input = tmp_bool;
}
}
+
+ break;
+ case FloatType:
+ if (width > 0)
+ tmp_str = QString(_num->ascii(width));
+ else
+ // rough estimate for maximal decimal precision (10^3 = 2^10)
+ tmp_str = QString(_num->ascii(3*mpf_get_default_prec()/10));
break;
default:
- tmp_str = QString(_num->ascii(prec));
+ return QString(_num->ascii());
}
-
- return tmp_str;
+
+ if (prec >= 0)
+ return roundNumber(tmp_str, prec);
+ else
+ return tmp_str;
}
void KNumber::setDefaultFloatOutput(bool flag)
diff -Nur kdeutils-3.5.0.orig/kcalc/knumber/knumber.h kdeutils-3.5.0/kcalc/knumber/knumber.h
--- kdeutils-3.5.0.orig/kcalc/knumber/knumber.h 2005-10-10 16:59:12.000000000 +0200
+++ kdeutils-3.5.0/kcalc/knumber/knumber.h 2006-01-16 19:40:41.000000000 +0100
@@ -45,7 +45,7 @@
* of this class will be described below:
*
* @li @p NumType::SpecialType - This type represents an error that
- * has occured, e.g. trying to divide 1 by 0 gives an object that
+ * has occurred, e.g. trying to divide 1 by 0 gives an object that
* represents infinity.
*
* @li @p NumType::IntegerType - The number is an integer. It can be
@@ -75,7 +75,7 @@
* KNumber tries to provide transparent access to the following type
* of numbers:
*
- * @li @p NumType::SpecialType - Some type of error has occured,
+ * @li @p NumType::SpecialType - Some type of error has occurred,
* further inspection with @p KNumber::ErrorType
*
* @li @p NumType::IntegerType - the number is an integer
@@ -134,7 +134,7 @@
* NumType::FractionType, which can be either displayed as fractions
* or in decimal notation.
*
- * The default behaviour is not to display fractions in floating
+ * The default behavior is not to display fractions in floating
* point notation.
*/
static void setDefaultFloatOutput(bool flag);
@@ -157,8 +157,8 @@
/**
* What a terrible method name!! When displaying a fraction, the
- * default mode gives "@p nomin/denom". With this method one can
- * choose to display a fraction as "@p integer nomin/denom".
+ * default mode gives @p "nomin/denom". With this method one can
+ * choose to display a fraction as @p "integer nomin/denom".
*
* Examples: Default representation mode is 47/17, but if @p flag is
* @p true, then the result is 2 13/17.
@@ -168,17 +168,19 @@
/**
* Return a QString representing the KNumber.
*
- * @param prec The string is similar to the optional conversion
- * specifications for formatted output for printf and friends,
- * e.g. "10.3" to display numbers with 10 digits in front of the
- * decimal point, and 3 after the decimal point. More precise
- * explanations will be given later.
- *
+ * @param width This number specifies the maximal length of the
+ * output, before the method switches to exponential notation and
+ * does rounding. For negative numbers, this option is ignored.
+ *
+ * @param prec This parameter controls the number of digits
+ * following the decimal point. For negative numbers, this option
+ * is ignored.
+ *
*/
- QString const toQString(QString const & prec = QString::null) const;
+ QString const toQString(int width = -1, int prec = -1) const;
/**
- * Compute the absoulte value, i.e. @p x.abs() returns the value
+ * Compute the absolute value, i.e. @p x.abs() returns the value
*
* \f[ \left\{\begin{array}{cl} x, & x \ge 0 \\ -x, & x <
* 0\end{array}\right.\f]
diff -Nur kdeutils-3.5.0.orig/kcalc/knumber/knumber_priv.cpp kdeutils-3.5.0/kcalc/knumber/knumber_priv.cpp
--- kdeutils-3.5.0.orig/kcalc/knumber/knumber_priv.cpp 2005-10-10 16:59:12.000000000 +0200
+++ kdeutils-3.5.0/kcalc/knumber/knumber_priv.cpp 2006-01-16 19:41:47.000000000 +0100
@@ -13,13 +13,16 @@
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
#include <math.h>
#include <config.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
#include <qregexp.h>
#include <qstring.h>
@@ -158,9 +161,9 @@
return *this;
}
-QString const _knumerror::ascii(QString const &num) const
+QString const _knumerror::ascii(int prec) const
{
- static_cast<void>(num);
+ static_cast<void>(prec);
switch(_error) {
case UndefinedNumber:
@@ -174,19 +177,21 @@
}
}
-QString const _knuminteger::ascii(QString const &num) const
+QString const _knuminteger::ascii(int prec) const
{
+ static_cast<void>(prec);
char *tmp_ptr;
- gmp_asprintf(&tmp_ptr, "%Zd", _mpz);
- QString ret_str = tmp_ptr;
+ gmp_asprintf(&tmp_ptr, "%Zd", _mpz);
+ QString ret_str = tmp_ptr;
#warning ok to free with delete?
- delete tmp_ptr;
- return ret_str;
+ delete tmp_ptr;
+ return ret_str;
}
-QString const _knumfraction::ascii(QString const &num) const
+QString const _knumfraction::ascii(int prec) const
{
+ static_cast<void>(prec);
char const *tmp_ptr = mpq_get_str(0, 10, _mpq);
QString ret_str = tmp_ptr;
#warning ok to free with delete?
@@ -195,12 +200,14 @@
return ret_str;
}
-QString const _knumfloat::ascii(QString const &num) const
+QString const _knumfloat::ascii(int prec) const
{
QString ret_str;
char *tmp_ptr;
-
- gmp_asprintf(&tmp_ptr, "%Fg", _mpf);
+ if (prec > 0)
+ gmp_asprintf(&tmp_ptr, ("%." + QString().setNum(prec) + "Fg").ascii(), _mpf);
+ else
+ gmp_asprintf(&tmp_ptr, "%Fg", _mpf);
ret_str = tmp_ptr;
@@ -320,7 +327,7 @@
-#warning _cbrt for now this is a stupid work around for now
+#warning _cbrt for now this is a stupid work around
static void _cbrt(mpf_t &num)
{
double tmp_num = cbrt(mpf_get_d(num));
diff -Nur kdeutils-3.5.0.orig/kcalc/knumber/knumber_priv.h kdeutils-3.5.0/kcalc/knumber/knumber_priv.h
--- kdeutils-3.5.0.orig/kcalc/knumber/knumber_priv.h 2005-11-08 23:29:27.000000000 +0100
+++ kdeutils-3.5.0/kcalc/knumber/knumber_priv.h 2006-01-16 19:40:41.000000000 +0100
@@ -46,7 +46,7 @@
virtual NumType type(void) const = 0;
- virtual QString const ascii(QString const &num = QString::null) const = 0;
+ virtual QString const ascii(int prec = -1) const = 0;
virtual _knumber * abs(void) const = 0;
virtual _knumber * intPart(void) const = 0;
@@ -90,7 +90,7 @@
virtual NumType type(void) const {return SpecialType;}
- virtual QString const ascii(QString const &num = QString::null) const;
+ virtual QString const ascii(int prec = -1) const;
virtual _knumber * abs(void) const;
virtual _knumber * intPart(void) const;
@@ -156,7 +156,7 @@
virtual NumType type(void) const {return IntegerType;}
- virtual QString const ascii(QString const &num = QString::null) const;
+ virtual QString const ascii(int prec = -1) const;
virtual _knumber * abs(void) const;
virtual _knumber * intPart(void) const;
@@ -216,7 +216,7 @@
virtual NumType type(void) const {return FractionType;}
- virtual QString const ascii(QString const &num= QString::null) const;
+ virtual QString const ascii(int prec = -1) const;
bool isInteger(void) const;
@@ -269,7 +269,7 @@
virtual NumType type(void) const {return FloatType;}
- virtual QString const ascii(QString const &num = QString::null) const;
+ virtual QString const ascii(int prec = -1) const;
virtual _knumber * abs(void) const;
virtual _knumber * intPart(void) const;
diff -Nur kdeutils-3.5.0.orig/kcalc/stats.cpp kdeutils-3.5.0/kcalc/stats.cpp
--- kdeutils-3.5.0.orig/kcalc/stats.cpp 2005-09-10 10:21:34.000000000 +0200
+++ kdeutils-3.5.0/kcalc/stats.cpp 2006-01-16 19:41:11.000000000 +0100
@@ -82,14 +82,6 @@
KNumber result = 0;
unsigned int bound;
size_t index;
- qHeapSort(mData);
-
-#ifdef DEBUG_STATS
- QValueVector<KNumber>::iterator p;
- for(p = mData.begin(); p != mData.end(); ++p) {
- printf("Sorted %Lg\n", *p)
- }
-#endif
bound = count();
@@ -101,12 +93,16 @@
if (bound == 1)
return mData.at(0);
+ // need to copy mData-list, because sorting afterwards
+ QValueVector<KNumber> tmp_mData(mData);
+ qHeapSort(tmp_mData);
+
if( bound & 1) { // odd
index = (bound - 1 ) / 2 + 1;
- result = mData.at(index - 1);
+ result = tmp_mData.at(index - 1);
} else { // even
index = bound / 2;
- result = ((mData.at(index - 1)) + (mData.at(index))) / KNumber(2);
+ result = ((tmp_mData.at(index - 1)) + (tmp_mData.at(index))) / KNumber(2);
}
return result;
Index: kdeutils.spec
===================================================================
RCS file: /cvs/dist/rpms/kdeutils/devel/kdeutils.spec,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- kdeutils.spec 5 Jan 2006 09:30:16 -0000 1.50
+++ kdeutils.spec 16 Jan 2006 18:58:06 -0000 1.51
@@ -9,7 +9,7 @@
%define disable_gcc_check_and_hidden_visibility 1
Version: 3.5.0
-Release: 3
+Release: 4
Name: kdeutils
Prefix: /usr
Summary: K Desktop Environment - Utilities
@@ -23,6 +23,9 @@
Patch1: kdf-3.0.2-label.patch
Patch2: kde-libtool.patch
+# upstream fixes
+Patch50: kdeutils-3.5.0-kcalc.patch
+
Requires: kdelibs >= 6:%{version}
Requires: kdebase >= 6:%{version}
@@ -240,6 +243,7 @@
%setup -q
%patch1 -p1 -b .label
%patch2 -p1 -b .libtool
+%patch50 -p1 -b .kcalc
%build
unset QTDIR || : ; . /etc/profile.d/qt.sh
@@ -320,6 +324,9 @@
%{_includedir}/kde/*
%changelog
+* Mon Jan 16 2006 Than Ngo <than at redhat.com> 6:3.5.0-4
+- apply patch to fix #176463
+
* Thu Jan 05 2006 Radek Vokal <rvokal at redhat.com> 6:3.5.0-3
- rebuilt against new libnetsnmp
- Previous message (by thread): rpms/lm_sensors/devel lm_sensors.init, 1.5, 1.6 lm_sensors.spec, 1.30, 1.31
- Next message (by thread): rpms/kudzu/devel .cvsignore, 1.96, 1.97 kudzu.spec, 1.109, 1.110 sources, 1.107, 1.108
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the fedora-cvs-commits
mailing list