quick easy question

This is a discussion on quick easy question within the C++ Programming forums, part of the General Programming Boards category; I know floats are not percise, as in, they are never EXACTELY what you set them. (1.0 might be somthing ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,627

    quick easy question

    I know floats are not percise, as in, they are never EXACTELY what you set them. (1.0 might be somthing like 1.000000001206 for example.)
    But are doubles percise, or do they do this haywire thing too?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    To some extent this is implementation defined, but if we're thinking about an IEEE float/double, then any number that only requires 23 bits to represent (with a floating binary point) can be represented exactly (so 1.0, 1.5, 1.25, 1.125, etc. can all be represented exactly, but 1.1 cannot). With doubles, it's 52 bits. So the same problem is there, it's just that the errors are farther down the line.

    Edit to add: Actually I forgot about the implicit one in front of the binary point -- so any number that's representable with 24 bits/53 bits works.
    Last edited by tabstop; 01-25-2008 at 12:57 PM.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,720
    I know floats are not percise, as in, they are never EXACTELY what you set them.
    I believe "precision" is usually used to refer to how many digits/bits can be used to represent a number (or to what decimal place some quantity can be measured), whereas "accuracy" considers how close to the actual value is its representation (or its measured value).

    1.0 might be somthing like 1.000000001206 for example.
    I do not think so, since 1.0 can be accurately represented in floating point.

    But are doubles percise, or do they do this haywire thing too?
    The problem with floating point inaccuracy is with any floating point scheme, regardless of the amount of precision. Take (1.0/3.0) for example.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,627
    Thanks. That is what I needed to know.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy String position question...
    By Striph in forum C Programming
    Replies: 4
    Last Post: 05-11-2009, 08:48 PM
  2. Quick Easy Question
    By St0rmTroop3er in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-24-2004, 12:08 AM
  3. Quick Question on File Names and Directories
    By Kyoto Oshiro in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2002, 01:54 AM
  4. * quick question *
    By SavesTheDay in forum C Programming
    Replies: 3
    Last Post: 03-27-2002, 05:58 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21