1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Double

Discussion in 'C++' started by techinspiration, Jun 15, 2010.

  1. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    I have just scared. I expect that is here with some mathematical and physical constants, and get for a particular value for my double variable

    "ExpTerm = 2.22184e-09"

    out. The next step, I reckon (x is also a double)
    Code:
     x = 1 - expTerm; 
    court <<"1 - expTerm = "<<x <<endl;
    However, the result gives me a "1 - 1 from expTerm ="!
    In such an accuracy could, of course I completely forgot my account immediately. How can I increase the accuracy?
     
  2. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    x = 1.0 - expTerm;
     
  3. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Hmm, this works for me no better:

    Code:
    # Include <iostream.h> 
    # Include <stdlib.h> 
    
    int main () 
    ( 
          double expTerm = 2.22184e-09; 
          court <<"expTerm = "<<expTerm <<endl; 
          expTerm expTerm = 1.0; 
          court <<"1.0 - expTerm = "<<expTerm <<endl; 
          system ("PAUSE"); 
          return 0; 
    )  
    is with me again
    "1.0-expTerm = 1"

    Is this due to my compiler, or at least to the number of Kleinhiet (exp ^ (-9))?
     
  4. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Actually, it should not be an issue, because according to the literature has a double
    64 bit and can therefore theoretically represent a range of + -1.7 * 10 ^ (-308).
    In <float.h> is also established that there are 52 double digits . This should actually be sufficient to calculate the difference specified correctly and also issue to ...
     
  5. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    court <<setprecision (12);
    are ne other 1
     
  6. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    in the numeric_limits <T> there is in the double epsilon ^ -16 which is the value at which one-value = 1: O)
     

Share This Page