我在ubuntu 64 位下, g++ 版本为 4.9 用 g++ -std=c++11 编译,使用cmath头文件,调试运行到sqrt时出错。下面是部分源码和调试信息:
源码:
trans(vc0, p4);
void trans(const vector<double> &v, vector<double> &p)
{
double vv=sqrt(v[1]*v[1]+v[2]*v[2]+v[3]*v[3]);
double ga=1.0/sqrt(1.0-vv*vv);
double ppar=p[1]*v[1]+p[2]*v[2]+p[3]*v[3];
double gavv=(ppar*ga/(1.0+ga)-p[0])*ga;
p[0]=ga*(p[0]-ppar);
p[1]=p[1]+v[1]*gavv;
p[2]=p[2]+v[2]*gavv;
p[3]=p[3]+v[3]*gavv;
}
调试:
571 trans(vc0, p4);
(gdb) s
trans (v=std::vector of length 4, capacity 4 = {…}, p=std::vector of length 4, capacity 4 = {…}) at LBT2.cc:2075
2075 double vv=sqrt(v[1]*v[1]+v[2]*v[2]+v[3]*v[3]);
(gdb) s
std::vector<double, std::allocator<double> >::operator[] (this=0x62a310 <vc0>, __n=1) at /usr/include/c++/4.9/bits/stl_vector.h:795
795 { return *(this->_M_impl._M_start + __n); }
(gdb) s
std::vector<double, std::allocator<double> >::operator[] (this=0x62a310 <vc0>, __n=1) at /usr/include/c++/4.9/bits/stl_vector.h:795
795 { return *(this->_M_impl._M_start + __n); }
(gdb) s
std::vector<double, std::allocator<double> >::operator[] (this=0x62a310 <vc0>, __n=2) at /usr/include/c++/4.9/bits/stl_vector.h:795
795 { return *(this->_M_impl._M_start + __n); }
(gdb) s
std::vector<double, std::allocator<double> >::operator[] (this=0x62a310 <vc0>, __n=2) at /usr/include/c++/4.9/bits/stl_vector.h:795
795 { return *(this->_M_impl._M_start + __n); }
(gdb) s
std::vector<double, std::allocator<double> >::operator[] (this=0x62a310 <vc0>, __n=3) at /usr/include/c++/4.9/bits/stl_vector.h:795
795 { return *(this->_M_impl._M_start + __n); }
(gdb) s
std::vector<double, std::allocator<double> >::operator[] (this=0x62a310 <vc0>, __n=3) at /usr/include/c++/4.9/bits/stl_vector.h:795
795 { return *(this->_M_impl._M_start + __n); }
(gdb) s
__sqrt (x=0) at w_sqrt.c:27
27 w_sqrt.c: No such file or directory.
(gdb) p p
No symbol “p” in current context.
(gdb) s
30 in w_sqrt.c
(gdb) s
__ieee754_sqrt (d=0) at ../sysdeps/x86_64/fpu/math_private.h:58
58 ../sysdeps/x86_64/fpu/math_private.h: No such file or directory.