Thread: Most Efficient Way to Check a Variable Is A Whole Number

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> it's not necessary to worry when comparing x and floor(x) if it is necessary to detect that a floating point variable x holds an integral value.

    What about my example? It gives incorrect output.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Daved View Post
    What about my example? It gives incorrect output.
    As a matter of fact, it gives correct output. Your code correctly detected that a floating point variable with the value (approximately) 42.993 does not contain an integral value.

    Your error was in expecting that the series of calculations that produced the value would yield an integral value.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf with variable number of entries
    By cfdprogrammer in forum C Programming
    Replies: 5
    Last Post: 04-20-2009, 02:02 AM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. Using loops for check a roman number input.
    By eryell in forum C++ Programming
    Replies: 9
    Last Post: 04-12-2006, 11:04 AM
  5. How is to check prime number?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-04-2001, 11:36 PM