由买买提看人间百态

topics

全部话题 - 话题: psum
(共0页)
vi
发帖数: 309
1
来自主题: Programming版 - g++ default optimization error
奇怪的问题,谁帮忙看一下,谢谢!
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
list tlist(arr, arr+(sizeof(arr)/sizeof(int)));
int psum;
for_each(tlist.begin(), tlist.end(), [&psum](int &_val) {
_val += psum;
psum = _val;
});
for (auto _val: tlist) { cout << _val << " "; };
cout << endl;
cout << *(tlist.begin());
}
g++ default:
$2 4 7 11 16 22 29 37 46
2$
if compile with -O1 then it will produce the correct output:
$1 3 6 10 15 21 28 36 45
1$
f******y
发帖数: 2971
2
来自主题: Programming版 - g++ default optimization error
一个很明显的问题是psum没有初始化。
a********r
发帖数: 92
3
来自主题: Computation版 - numeric recipe code amotry(), bug or not
in function amotry() for downhill simplex minimization,
why fac2=fac2=fac1-fac; instead of fac2=-fac;
then this may not be a reflection or extrapolation, because
ytry[j] = center * (1-fac) + p[ihi][j]*face - (1-fac)/ndim * p[ihi][j]
the first two terms is the extrapolation, what's the point for the 3rd term?
It will be incorrect in some case, reflection will not be reflection anymore.
float amotry(float **p, float y[], float psum[], int ndim,
float (*funk)(float []), int ihi, float fac)
Extrapo
g***s
发帖数: 3811
4
来自主题: Computation版 - C 语言问题
Numerical recipes in C [electronic resource] : the art of scientific computing
/ William H. Press ... [et al.].中的一个函数一开始有这样一个宏:
#define GET_PSUM \
for (j=1;j<=ndim;j++) {\
for (sum=0.0,i=1;i<=mpts;i++) sum+=p[i][j];\
psum[j]=sum;}
我的问题是这里的三个反斜杠,"\",是什么意思?
是不是那本书作者在排版的时候想说,要把这四行写在同一行中? 要是这样的话,我在edit
的界面中一行写不下怎么办?
初级问题,见笑了
(共0页)