need system error-code.

Discussion in 'C Programming' started by Holger.Rostalski@gmx.de, May 15, 2007.

  1. Guest

    hello
    i have an very old code here, wich worked long time very well.
    but now i 've got a bugreport that there is a problem with "nan" for
    delta_sigma.

    in my code is a very long math-calculation


    ==============
    delta_sigma = b * sinus_sigma * (cosinus_2_sigma_m + 0.25 * b *
    (cosinus_sigma * (-1. + 2. *
    cosinus_2_sigma_m_q) -
    (1. / 6.) * b * cosinus_2_sigma_m * (-3. + 4. *
    sinus_2_sigma) * (-3. + 4. *
    cosinus_2_sigma_m_q)));
    ==============

    all used variables are from the type double and are in all cases valid
    but close to zero. and sinus_sigma is exact zero.

    normaly the result has to be delta_sigma==0 but here it is "nan"

    when i split the calculation into parts like


    ================================
    term1=(cosinus_2_sigma_m + 0.25 * b *
    (term4 - (1. / 6.) * b * cosinus_2_sigma_m
    *term3 * term 2 )

    term2=(-3. + 4. * cosinus_2_sigma_m_q)
    term3= (-3. + 4. * sinus_2_sigma)
    term4=cosinus_sigma * (-1. + 2. * cosinus_2_sigma_m_q)

    delta_sigma = b * sinus_sigma * term1;
    ================================
    now delta_sigma isnt "nan" and the result is right delta_sigma==0


    i work with the gnu-compiler g++.


    it looks like a problem with the accuracy of a double-value.


    Now the question
    ============
    Is it possible to get an errorcode from the system about this
    calculation? Or is there an other way to solve this problem?
     
    , May 15, 2007
    #1
    1. Advertising

  2. Guest

    correction

    sinus_sigma isnt exact zero but also very close to zero.
     
    , May 15, 2007
    #2
    1. Advertising

  3. "" <> writes:
    > i have an very old code here, wich worked long time very well.
    > but now i 've got a bugreport that there is a problem with "nan" for
    > delta_sigma.

    [snip]
    > i work with the gnu-compiler g++.


    g++ is a C++ compiler, not a C compiler. It's likely that your
    problem would occur either in C or in C++, but we can't be sure.

    Either recompile your code using "gcc" or some other C compiler, or
    post to comp.lang.c++.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, May 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sfunds sfunds
    Replies:
    9
    Views:
    8,727
  2. Matt
    Replies:
    2
    Views:
    838
    Matt Getting
    Jul 24, 2003
  3. Simon Harris
    Replies:
    2
    Views:
    2,618
    Simon Harris
    Apr 27, 2005
  4. Wagner Dias
    Replies:
    3
    Views:
    3,058
    Andre Kostur
    Mar 28, 2005
  5. Sergeant_Pepper

    Return-Code of "system" on a 64-bit system

    Sergeant_Pepper, Dec 18, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    98
    Sergeant_Pepper
    Dec 19, 2005
Loading...

Share This Page