[Qt-interest] Why 1/255 is 0 ?
Dan White
ygor at comcast.net
Wed Oct 13 16:29:03 CEST 2010
You are missing the significance of math operations with integers as opposed to floating point numbers.
Integer 1 / integer 255 = 0
1.0 / 255.0 = 0.003921569
the definition for the function you are using is qreal qPow ( qreal x, qreal y )
So your statement should read:
qPow( (qreal(i)/255.0),qreal(j) );
j/1 is wasted operation.
“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)
----- Hannu Shemeikka <hps at shemeikka.org> wrote:
> Hi,
>
> Could someone explain me this:
>
> double c = 1/255;
>
> and c is 0 after watching it in debugger. It should be 0,003921569.
> I tried float and few others but no success.
>
> The real thing where I need that division is qPow((i/255),(j/1)); //
> i<255 and j<8
>
> What am I missing here? I'm using Ubuntu 10.10 and Qt 4.7
>
> - Hannu
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list