Thread: basic c++ variable types, digits of precision etc

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    basic c++ variable types, digits of precision etc

    Hi

    Please have a look on this table:
    http://img192.imageshack.us/img192/4...ledatatype.jpg

    "int" is system dependent and on 32-bit system occupies four bytes. As there are 8 bits in one byte therefore there are total 32 bits. If 2 is raised to the power of 32, 2^(32), it comes to 4294967296 which is equal to combined numerical range of int (2,147,483,648 + 2,147,483,647). The same is true for other variable types except "float" and "double". Why is so?

    Is "float" also system dependent like "int?

    What does the digits of precision, 7 and 15, for "float" and "double" respectively mean? Does this mean decimal point is followed by 7 and 15 digits respectively?

    It would be very nice of you if you would help me with the above queries. Please keep the things simple.

    Regards
    Jackson
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Is "float" also system dependent like "int?
    Yes, but variation is less common. The C standard follows what IEEE defines, which in turn is what comes available in hardware FPU's. There is always scope to implement a float with more bits allocated to it, but it would be a lot of work for the implementer.

    > Does this mean decimal point is followed by 7 and 15 digits respectively?
    No, it means the left-most N digits (regardless of the decimal point)
    So
    123456789
    123.456789
    0.000123456789
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    The floating point variables have a more complex representation. But if you study how they are represented you can then understand where those numbers come from.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Floating point essentially uses scientific notation.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-21-2009, 08:52 PM
  2. Counting number of digits in a variable
    By Saeid87 in forum C Programming
    Replies: 6
    Last Post: 06-05-2009, 01:13 PM
  3. Extending basic data types.
    By nempo in forum C++ Programming
    Replies: 23
    Last Post: 09-25-2007, 03:28 PM
  4. float/double variable storage and precision
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 07-28-2003, 06:23 PM
  5. Basic Data types help
    By viryonia in forum C Programming
    Replies: 6
    Last Post: 03-10-2003, 11:00 AM