Thread: Comparing 2 floats, off by 1

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153

    Comparing 2 floats, off by 1

    I understand that 1.2 cannot be represented perfectly with a float. But I am getting an off by 1 (or really off by .99998) error and I am convinced it not due to array indexes but by floating point weirdness. Is there some reason that the mantissa would be disregarded in a greater than comparison. e.g.
    if (2.999 < 2.0) would evaluate to true?
    Last edited by javaeyes; 11-29-2012 at 11:33 AM. Reason: mistake

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Floats
    By okel91 in forum C Programming
    Replies: 7
    Last Post: 03-17-2010, 04:00 PM
  2. efficiency comparing ints and floats
    By MK27 in forum C Programming
    Replies: 14
    Last Post: 02-28-2009, 03:56 PM
  3. comparing two arrays of floats
    By COBOL2C++ in forum C++ Programming
    Replies: 7
    Last Post: 07-16-2003, 03:22 AM
  4. comparing numbers(floats)
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-30-2002, 09:12 AM
  5. Floats
    By JFK in forum C Programming
    Replies: 2
    Last Post: 11-27-2001, 07:53 AM