[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: dump question
From: Christian Esken <c.esken () cityweb ! de>
Date: 1999-08-08 17:09:40
[Download RAW message or body]
On Sun, 08 Aug 1999 Uwe Thiem wrote:
>I'm stuck with a little problem I'm too dump to solve it seems. Maybe
>someone else can shed some light on it.
>
>This is the code:
>
>double tmp = mRealCenter - mRealWidth / 2.0;
>
>QString s;
>s.setNum( tmp, 'f', 60 );
>cerr << s << "\n";
>for ( i = 0, p = mReals; i < 3; i++, p++ )
> {
> s.setNum( (double) i * mRealWidth / (double) mWidth, 'f', 60 );
> cerr << s << "\n";
> s.setNum( tmp + (double) i * mRealWidth / (double) mWidth, 'f', 60 );
I would bet the problem is in above line: Doing setNum() converts.
An implicit cast will happen to "tmp". It might be converted to "anything"
appropiate, for example to int or float. float could be a too small data type.
Solution: Always store the data in appropiate datas types.
IMO storing a float (double) in a string and then resuing it to do
calculations is a very dangerous way of handling data, IMO.
I didnīt test the following code, but I think it works out OK.
double d_tmp;
d_tmp = double(tmp)
for ( i = 0, p = mReals; i < 3; i++, p++ )
{
QString s;
double a,b;
a = (double) i * mRealWidth / (double) mWidth;
cerr << a << "\n";
b = d_tmp + a;
cerr << b << "\n";
s.setNum( b, 'f', 60 );
cerr << s << "\n";
}
cerr << "\n";
Christian
--
Is Unix ready for the desktop? See http://www.kde.org
The Christian Esken
|/ Desktop KDE Developer
|\ Environment esken@kde.org
KDE - The net transparent free Unix Desktop for everyone
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic