Thread: Is it an error or am i wrong

  1. #1
    Registered User
    Join Date
    Mar 2013

    Lightbulb Is it an error or am i wrong

    Hey guys im novice c prog and i am reading the book "jumping into c++".
    Im in the first few pages and i came across a problem.
    attached is a screenshot of my problem.
    Is it a printing mistake or have i messed up?
    This is pg 59 of the " jumping into C++"
    Im really enjoying this book.
    Isn't it supposed to be 264 because a double is 8 bytes (8bytes x 8bits=64bits)
    please guide me!
    Attached Images Attached Images Is it an error or am i wrong-screen-shot-2013-03-05-5-58-01-pm-png 

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    But those 64 bits are split up into a significand and exponent.

    Yes it can store numbers up to 10^308, but it's only the first 15 digits which are actually stored within those 8 bytes.
    The rest of the number isn't stored at all (hence significant digits).

    It's a trade-off between a very large dynamic range and a small compact storage format.

    It does however mean you have to be really careful when combining numbers with very different exponents.
    10^100 + 1 will still be 10^100. You see, 1 is just far too small to be of any significance to 10^100.

    If you really wanted to store ALL the digits of 10^308 in complete accuracy, you would need a number containing 128 bytes of memory, not 8 bytes.
    Such things are possible with a multi-precision library, but you have to do some work yourself.
    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
    Join Date
    Mar 2013
    oh okok i get it now !!

    thank you.

  4. #4
    Registered User
    Join Date
    May 2003
    You are right, though, there is a typo in the book.

    There are 2^64 possible bit patterns that can be stored in 8 bytes, so there cannot be more than 2^64 different double precision floating point numbers. In fact there are slightly less since not every bit pattern represents a legal value.

    The number they print out, though, IS 2^64 - they had the expanded form correct but the simpler form mistyped.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No Output No Error what's wrong in the code
    By mkbutan in forum C Programming
    Replies: 4
    Last Post: 08-03-2012, 04:50 PM
  2. Replies: 3
    Last Post: 05-11-2011, 02:53 PM
  3. Error in my code...not sure what i did wrong
    By Gart08 in forum C Programming
    Replies: 24
    Last Post: 11-28-2010, 11:54 AM
  4. Error in printf line,,,what's wrong?
    By mft_ika in forum C Programming
    Replies: 9
    Last Post: 03-19-2010, 08:46 PM
  5. Nothing wrong!!! And yet I get this error:
    By Queatrix in forum C++ Programming
    Replies: 8
    Last Post: 01-10-2006, 03:06 PM

Tags for this Thread