English 中文(简体)
Fortran和C++所计算的数值之间的差异
原标题:Discrepancy between the values computed by Fortran and C++

我敢说,由Fortran和C++计算得出的数字数值将更加相似。 然而,从我所经历的情况来看,计算数字在数字太少后开始出现差异。 在将某些遗产法典从前语言传给后一种语言的过程中,我已经走过这个问题。 原来的第77号法典......

  INTEGER M, ROUND
  DOUBLE PRECISION NUMERATOR, DENOMINATOR

  M = 2
  ROUND = 1
  NUMERATOR=5./((M-1+(1.3**M))**1.8)
  DENOMINATOR = 0.7714+0.2286*(ROUND**3.82)
  WRITE (*,  (F20.15) ) NUMERATOR/DENOMINATOR
  STOP

......产出<>0.842201471328735,而C++当量......

int m = 2;
int round = 1;
long double numerator = 5.0 / pow((m-1)+pow(1.3, m), 1.8);
long double denominator = 0.7714 + 0.2286 * pow(round, 3.82);
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(15)
          << numerator/denominator << std::endl;
exit(1);

页: 1 也就是说,计算出来的数值等于,直到第6条标准>为止。 尽管我不是特别的反对者,但我感到倾向于认为其结果是正确的,因为它具有珍爱号的合法声誉。 然而,我对计算价值之间的这一差异的原因作了解释。 是否有任何人知道这一差异的原因?

最佳回答

部分而言,按违约计算,浮动点字面为单一精确度,而在C/C++则如此。 它们是双重精确。

因此,在你的定本中,计算NUMERATOR的表述是完全精确的;在将最后结果分配给NUMERATOR变量时,这一表述只能变成双重精确。

计算分配给丹麦劳动力评估变量的价值的表述也一样。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?