[Qt-interest] Why 1/255 is 0 ?

Jari Fredriksson jarif at iki.fi
Wed Oct 13 18:16:58 CEST 2010


On 13.10.2010 17:45, Hannu Shemeikka wrote:
> Well,
> 
> That was a stupid mistake :D :blush
> 
> Wonder why I didn't notice that..hmm..well..long day and I was being
> stupid.
> 
> Thanks for quick answers
> 

I wonder if the Qt version has anything to do with the result :P

Sorry ;)




> - H
> 
> On Wed, 2010-10-13 at 10:37 -0400, Atlant Schmidt wrote:
>> All:
>>
>>> Also:
>>>        double c = 1.0 / 255;
>>>        double c = 1 / 255.0;
>>
>>   Heck, go for broke and say:
>>
>>     double c = 1.0 / 255.0;
>>
>>   Generally speaking, in just about any language, when you
>>   intend a number to be considered as a floating point number,
>>   you should *STATE* it as a floating point number. That avoids
>>   any possibility of ambiguity between you and the compiler/
>>   interpreter.
>>
>>   And don't just write it as "1." -- "1.0" is a lot more
>>   "visible" to a future maintainer.
>>
>>                        Atlant
>>
>> -----Original Message-----
>> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Thiago Macieira
>> Sent: Wednesday, October 13, 2010 10:28
>> To: qt-interest at trolltech.com
>> Subject: Re: [Qt-interest] Why 1/255 is 0 ?
>>
>> On Wednesday 13. October 2010 16.15.27 Reece Dunn wrote:
>>> On 13 October 2010 15:11, Hannu Shemeikka <hps at shemeikka.org> wrote:
>>>> Hi,
>>>>
>>>> Could someone explain me this:
>>>>
>>>> double c = 1/255;
>>>
>>> That is an integer division that is rounded to the nearest whole integer.
>>>
>>> Try:
>>>
>>>     double c = double(1)/255;
>>
>> Also:
>>         double c = 1.0 / 255;
>>         double c = 1 / 255.0;
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>   Senior Product Manager - Nokia, Qt Development Frameworks
>>       PGP/GPG: 0x6EF45358; fingerprint:
>>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>>
>> This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.
>>
>> Thank you.
>>
>> Please consider the environment before printing this email.
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest


-- 

You attempt things that you do not even plan because of your extreme
stupidity.



More information about the Qt-interest-old mailing list