Results 1 to 17 of 17

Thread: little q: illogical logical more c++

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: little q: illogical logical more c++

    If the value you are testing for equality to 1.00 (exactly) is the result of a computation then the approximation of the result may not be exactly 1.00. Some numbers cannot be exactly represented in a fixed length binary floating point form, and doing maths on them can lead to the situation where these approximation errors accumulate. You can end up with a floating point value that differs from the exact value at the 15 th decimal place and 1.0 != 1.00000000000001. This is why people keep telling you about qFuzzyCompare().

    What Every Computer Scientist Should Know About Floating-Point Arithmetic

    In your situation, where you seem to be working with money, you may well be better off working strictly with integer numbers of cents.
    Last edited by ChrisW67; 30th June 2015 at 22:22.

Similar Threads

  1. Suggestions for logical expression syntax?
    By rakkar in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2009, 21:24
  2. Non logical Errors - qmake
    By ahmhdy in forum Qt Programming
    Replies: 7
    Last Post: 19th June 2009, 22:11
  3. Replies: 0
    Last Post: 24th November 2008, 09:52
  4. little logical question........
    By sudheer in forum Qt Tools
    Replies: 3
    Last Post: 8th May 2008, 15:15
  5. Logical fonts?
    By sdfisher in forum Qt Programming
    Replies: 1
    Last Post: 1st March 2007, 14:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.