Velocity Reviews > need system error-code.

# need system error-code.

Holger.Rostalski@gmx.de
Guest
Posts: n/a

 05-15-2007
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?

Holger.Rostalski@gmx.de
Guest
Posts: n/a

 05-15-2007
correction

sinus_sigma isnt exact zero but also very close to zero.

Keith Thompson
Guest
Posts: n/a

 05-15-2007
"(E-Mail Removed)" <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <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"