double range

This is a discussion on double range within the C Programming forums, part of the General Programming Boards category; hi Am I right in saying that a double can hold a range of: +/- 2.2 E-308 to +/- 1.8 ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    11

    double range

    hi
    Am I right in saying that a double can hold a range of:
    +/- 2.2 E-308 to +/- 1.8 E308 (8 bytes)

    If so then should
    1.797693134862315907729305190789e+308
    fit in a double variable
    the above is 2^1024 which I did in the windows calculator, but when I do pow( 2, 1024 ) I get the 1.#INF00.
    Any advice or help much appreciated

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by paul_uk
    Am I right in saying that a double can hold a range of:
    +/- 2.2 E-308 to +/- 1.8 E308 (8 bytes)
    That is quite likely. You may want to verify the DBL_MAX on your system.
    Quote Originally Posted by paul_uk
    If so then should
    1.797693134862315907729305190789e+308
    fit in a double variable
    the above is 2^1024 which I did in the windows calculator, but when I do pow( 2, 1024 ) I get the 1.#INF00.
    Any advice or help much appreciated
    I don't suppose this is too much help, but I see similar results.
    Code:
    #include <stdio.h>
    #include <math.h>
    #include <float.h>
    
    int main(void)
    {
       double value = log(DBL_MAX) / log(2.0);
       printf("DBL_MAX = %f\n", DBL_MAX);
       printf("value = %g\n", value);
       value = pow(2.0, 1024.0);
       printf("value = %g\n", value);
       return 0;
    }
    
    /* my output
    DBL_MAX = 1.797693134862315708000000000000000000000e+308
    value = 1024
    
    pow: OVERFLOW error
    value = +INF
    */
    I think this decimal approximation may hide the fact the pow(2,1024) is "one" more than the largest double. That is, if we could use hexadecimal floating-point constants, perhaps DBL_MAX is defined like this.
    Code:
    DBL_MAX 0X1.fffffffffffffP1023 // hex constant
    Last edited by Dave_Sinkula; 03-02-2005 at 05:13 PM. Reason: Added color and finger quotes.
    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.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 11:53 AM
  3. what this error message says?
    By turkertopal in forum C++ Programming
    Replies: 4
    Last Post: 04-16-2006, 03:44 PM
  4. Please HELP!!
    By traz in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2003, 10:20 PM
  5. getline problem
    By scottmanc in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2003, 10:27 PM

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