我尝试编写一个简单的程序来练习Expection
C++,但我无法捕获和处理浮点异常?
这是我的代码。
#include <iostream>
#include <string>
#include <exception>
using namespace std;
int main(int argc, char **argv) {
int num_1[] = {0, 2, 4, 6, 8}, num_2[] = {3, 2, 1, 0, -1};
for(int i = 0; i < sizeof(num_1) / sizeof(num_1[0]); i++) {
try {
int result = num_1[i] / num_2[i];
printf("%d / %d = %d\n", num_1[i], num_2[i], result);
} catch(exception &e) {
cout << e.what() << endl;
cout << "something is wrong." << endl;
continue;
}
} …
Run Code Online (Sandbox Code Playgroud) A和B是矢量或长度N,其中N可以在20到200的范围内.我想计算这些向量之间距离的平方,即d ^ 2 = || AB || ^ 2.
到目前为止,我有:
float* a = ...;
float* b = ...;
float d2 = 0;
for(int k = 0; k < N; ++k)
{
float d = a[k] - b[k];
d2 += d * d;
}
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,除了我已经分析了我的代码,这是瓶颈(超过50%的时间花在这上面).我在Win 7上使用Visual Studio 2012,具有以下优化选项:/O2 /Oi /Ot /Oy-
.我的理解是VS2012应该自动矢量化该循环(使用SSE2).但是,如果我#pragma loop(no_vector)
在代码中插入我没有明显减慢速度,所以我猜这个循环没有被矢量化.编译器通过以下消息确认:
info C5002: loop not vectorized due to reason '1105'
Run Code Online (Sandbox Code Playgroud)
我的问题是:
reason '1105'
?