Review Request: KColorSpace::KHCY::KHCY(const & QColor) constructor floating point precision error

Michael Pyne mpyne at kde.org
Tue Jun 23 21:59:12 BST 2009


On Tuesday 23 June 2009 01:52:18 Oswald Buddenhagen wrote:
> On Mon, Jun 22, 2009 at 07:15:39PM -0400, Michael Pyne wrote:
> > I think the best answer in this case is to ensure as much as possible,
> > comparisons are done against 0.0 (i.e. don't do if (a == b), but do c = a
> > - b; if(c == 0.0) )
>
> i really have to wonder what the technical foundation of that idea is,
> because to me it doesn't make any sense.

Well if all you're really worried about is dividing against zero then you can 
compare against 0.0 (which is really the only equality comparison you can do 
on floating point since it is exact and so are its conversions to different 
forms).

You do need to make sure that the value you're dividing by is the value you're 
comparing against though, which is why I recommended using the named temporary 
variable.  I suppose this doesn't work if the division will be performed at a 
lower precision (which from my understanding of x86, could happen when using 
the FPU), since what is not quite zero as an 80-bit double could be converted 
to a 64-bit zero.

If we're really that worried about it I think Olivier's solution would be just 
fine (i.e. qFuzzyCompare).

Regards,
 - Michael Pyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090623/494433e1/attachment.sig>


More information about the kde-core-devel mailing list