n**********E 发帖数: 157 | 1 I am sorry that the original post is misleading. Please see the detailed description of the problem below.
They are a lot of floating point calculation in the code.
Basically, i am doing an interpolation from a position to the
closest grid point. It is a 1d problem.
The domain is from (-L, L) and N is the number of grid point at a half
domain.
The grid size is dv, where dv = L/N; The grid is cell centered (-0.5
in the code below).
L, dv are declared to be double type and N to be integer type.
Be | r*********r 发帖数: 3195 | 2 because your code has bugs. | n**********E 发帖数: 157 | 3 more details? thank you.
【在 r*********r 的大作中提到】 : because your code has bugs.
| r*********r 发帖数: 3195 | 4 compile and run the following code, what do u get?
#include
int main(int argc, char *argv[])
{
double a = 1.66e-02;
double b = 8.15e-04 ;
double q = 1.0 - a + b;
std::cout << q << std::endl;
return 0;
} | e*****n 发帖数: 124 | | e*****n 发帖数: 124 | 6 i am with g++ 4.4.1 on 64 bit ubuntu btw. | L***n 发帖数: 6727 | 7 i got this number too, gcc 4.3,3 ubuntu x86-32
【在 e*****n 的大作中提到】 : i got 0.984215
| f**********e 发帖数: 66 | 8 omg, I also got 0.984215!
what's wrong in it? | e*****n 发帖数: 124 | 9 我感觉你在打印v,dv,N,j0,a,b之后,打印q,q0之前改变了,N,v,dv那些东西的值
description of the problem below.
【在 n**********E 的大作中提到】 : I am sorry that the original post is misleading. Please see the detailed description of the problem below. : They are a lot of floating point calculation in the code. : Basically, i am doing an interpolation from a position to the : closest grid point. It is a 1d problem. : The domain is from (-L, L) and N is the number of grid point at a half : domain. : The grid size is dv, where dv = L/N; The grid is cell centered (-0.5 : in the code below). : L, dv are declared to be double type and N to be integer type. : Be
| y***d 发帖数: 2330 | 10 我觉得你可能有些 typo 什么的,但是你贴出来的这些代码都是你又整理过的,所以具
体什么问题很难看出来。
你实际的运算可能实际是对数组操作,所以也可能有数组越界或者坐标算错的情况。
比如说 v=-L+0 的时候,v/d+(N-0.5)=-0.5, j0=-1, 如果你把 j0 当坐标,就会出问
题;
再看 v=L-0 的时候,v/d+(N-0.5)=2N-0.5, j0=2N-1, j0 实际上有 2N+1 个值,如果
你只分配了 2N 个元素,就会有问题;
不管如何,我觉得你这个 j0 似乎有问题。
description of the problem below.
64bits.b
【在 n**********E 的大作中提到】 : I am sorry that the original post is misleading. Please see the detailed description of the problem below. : They are a lot of floating point calculation in the code. : Basically, i am doing an interpolation from a position to the : closest grid point. It is a 1d problem. : The domain is from (-L, L) and N is the number of grid point at a half : domain. : The grid size is dv, where dv = L/N; The grid is cell centered (-0.5 : in the code below). : L, dv are declared to be double type and N to be integer type. : Be
| n**********E 发帖数: 157 | 11 Thanks.I will double check that.
【在 y***d 的大作中提到】 : 我觉得你可能有些 typo 什么的,但是你贴出来的这些代码都是你又整理过的,所以具 : 体什么问题很难看出来。 : 你实际的运算可能实际是对数组操作,所以也可能有数组越界或者坐标算错的情况。 : 比如说 v=-L+0 的时候,v/d+(N-0.5)=-0.5, j0=-1, 如果你把 j0 当坐标,就会出问 : 题; : 再看 v=L-0 的时候,v/d+(N-0.5)=2N-0.5, j0=2N-1, j0 实际上有 2N+1 个值,如果 : 你只分配了 2N 个元素,就会有问题; : 不管如何,我觉得你这个 j0 似乎有问题。 : : description of the problem below.
|
|