accuracy

This is a discussion on accuracy within the C++ Programming forums, part of the General Programming Boards category; i recently wrote a money-involved program and am just wondering: [list=1][*]is it normal for a float to be inaccurate to ...

  1. #1
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787

    accuracy

    i recently wrote a money-involved program and am just wondering:

    [list=1][*]is it normal for a float to be inaccurate to the hundredth/thousandth?[*]what is the accuarcy (approx, of course) of a float[*]what is the accuracy of a double[*]any good algorithms for rounding to a certain number of decimal places (like setprecision, except with rounding)[/list=1]

    i'm not sure if all this has to do with the OS/System, but yeah...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I haven't read through the entire thread, but there might be something helpful here
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    I read most of that post, and it seems to have failed to mention one very critical point about why the inacuraccies occur. You're dealing with base 10 decimal numbers. The computer is dealing with base 2 decimal numbers. Given a small mantissa, it is difficult to represent one as the other with perfect accuracy. So, to answer (1), yes.

    For (2) and (3), the answer is in C++PL, I believe (under numeric limits), but I have no idea where my copy of it is right now.

    For (4), take the number of digits you want, and then look at the one following it (by dividing by the appropriate power of 10). This'll be better for printing than storing, as if the machine could not accurately represent the number once, it probably won't be able to the second time.

    Hope this is at least somewhat useful.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Cheers
    Just wondering, are you from Britain? Everyone I know from there says that
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Zach L.
    For (2) and (3), the answer is in C++PL, I believe (under numeric limits), but I have no idea where my copy of it is right now.
    what is that and where can i get it?

    I also didn't think about the binary thing... if forgot about that...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Actually, I'm from the small, third-world country of New Mexico.

    Sorry 'bout the acronym. C++PL is Stroustrup's The C++ Programming Language : Special Edition. It really is a great reference. Anyways, it talks about the numeric_limits templated class in <limits>. Essentially, its a specialized type which has a lot of machine-independent information (consequently, the exact values will vary). However, the examples he uses are of fairly common representations for floats/doubles/etc.

    For example (I dug it off the book shelf), for a float, it gives a base 2 mantissa of 24 bits (approx. 6 decimal digits), and an epsilon of 1.19...E-7 (that is, the smallest epsion such that 1.0 + epsilon != 1.0 within machine limits).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    thanks... i'll look into getting a copy... now i just need money
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Lots of Australians also say cheers.

    I just recently bought a copy of Stroustrups C++PL, also effective C++ and Programming Windows, talk about expensive!

    C++PL is difficult to read after reading Shidlt, Shidlt is a good writer, even if he's not a good coder.

    I'm sure it's a good book but wow, he goes into some advanced $$$$ in the first 4 chapters, if I was newbie at C++ I would burn the thing. First thing he talks about is user defined types, then he goes onto the basics of STL.
    Last edited by HybridM; 10-14-2003 at 07:59 AM.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  9. #9
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    It is an excellent reference. For the faint of heart, or those unfamiliar with the language already though, it can be rough. It is good for learning advanced stuff though.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  10. #10
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    I use it as a reference also. But I think it starts on chapter 4 (or maybe 5??) with the real learning stuff. Chapters 1-3 are just introduction, which may be why its even harder to read.

  11. #11
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Zach L.
    It is an excellent reference. For the faint of heart, or those unfamiliar with the language already though, it can be rough. It is good for learning advanced stuff though.
    what would you call advanced?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mouse accuracy
    By joed in forum Windows Programming
    Replies: 3
    Last Post: 06-25-2005, 05:52 PM
  2. Speeding up the computation without losing accuracy
    By u05rdh in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2003, 11:17 AM
  3. z-buffer accuracy
    By genghis in forum Game Programming
    Replies: 10
    Last Post: 08-17-2003, 08:58 AM
  4. Accuracy changes under different modes
    By sundeeptuteja in forum Tech Board
    Replies: 3
    Last Post: 07-09-2003, 12:02 AM
  5. changing accuracy of output from an input value
    By GCobbz in forum C Programming
    Replies: 1
    Last Post: 03-26-2003, 12:24 PM

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