Thread: Floating point #'s, why so much talk about it?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    7

    Floating point #'s, why so much talk about it?

    I dont get why floating points are such a big deal in C, as I am reading my C book and it seems like they put a lot of emphasis on floating point. But all that I get is that floating point #'s are basically decimal #'s. What more is to say about it?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    On many computers that use IEEE floating point standards, floats and doubles are inaccurate. Many floats cannot be represented accurately, and compring two floats (or double) for equality may fail when logic says they should be the same. Higher-level mathametical problems will have more use for floats/doubles than you find in most "normal" applicaton programs.
    Last edited by Ancient Dragon; 09-20-2005 at 02:45 PM.

  3. #3
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Basically, the point is, don't think "floating point number." Think "floating point approximation."

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    Thanks, I am reading a nice wikipedia article on floating point right now. Quick question why does it not print "10.2" but "10.200000"

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    float value = 10.2;
    printf("The number is %f\n", value);
    return 0;
    }

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >Quick question why does it not print "10.2" but "10.200000"
    http://dev.unicals.com/c89-draft.html#4.9.6.1
    f The double argument is converted to decimal notation in the style [-]ddd.ddd , where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal-point character appears, at least one digit appears before it. The value is rounded to the appropriate number of digits.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    thanks mate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 12:56 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. floating point binary program, need help
    By ph34r me in forum C Programming
    Replies: 4
    Last Post: 11-10-2004, 07:10 AM
  4. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 10:48 PM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM