代码似乎跳过了while循环:

int i,j;
i= floor((Lx-23.61)/0.1);
j=0;
while(Nh - modSED[i][j] > 0.0){
    j++;
}
if(j>0 && modSED[i][j]-Nh > Nh-modSED[i][j-1]){
    fileNH=modSED[i][j-1];
}else{
    fileNH=modSED[i][j];
}

这或多或少是通过一个双精度数组进行的粗略线性搜索(i-index是由代码的另一部分预先设置的,不应该是问题)当我看到GDB时,代码看起来有点不正常:
Breakpoint 1, mag (filter=4, Lx=23.930108812418158, z=0.57071772467724535, Nh=0.011911981460606383) at infopt.c:45
45      while(Nh-modSED[i][j]>0.0){
(gdb) print Nh-modSED[i][j]
$1 = 0.001911981460606383
(gdb) n
48      if(j>0 && modSED[i][j]-Nh > Nh-modSED[i][j-1]){
(gdb)

它刚刚跳过了j++段,尽管while循环的计算结果应该是true。
谢谢,
乔希

最佳答案

似乎是由于浮点比较而逐渐出现的错误众所周知,浮点比较并不十分安全有关更多信息,请参阅以下内容:
http://floating-point-gui.de/errors/comparison/
How dangerous is it to compare floating point values?
第二个链接对浮点操作有非常详细的解释

09-25 21:14