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

Atlant Schmidt aschmidt at dekaresearch.com
Wed Oct 13 16:37:12 CEST 2010


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.




More information about the Qt-interest-old mailing list