Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在做一些矩阵运算,其中矩阵元素通过以下方式从某些变量中获取值:
elem[1] = -x
但是当x = 0它设置-0在矩阵中时,这是不可取的。有什么明确的方法可以防止这种情况吗?
x = 0
-0
您可以执行以下操作:
elem[i] = -x + 0.0;
我已经测试了以下代码:
float a = -0.0; printf("%f %f\n", a, a + 0.0);
产生以下输出:
-0.000000 0.000000