出于某种原因,我收到以下警告
filename.cpp:99:53: warning: narrowing conversion of ‘sin(((double)theta))’ from ‘double’ to ‘float’ inside { } [-Wnarrowing]
filename.cpp:99:66: warning: narrowing conversion of ‘cos(((double)theta))’ from ‘double’ to ‘float’ inside { } [-Wnarrowing]
这听起来像是在尝试使用“double cos(double)”等而不是“float cos(float)”等。我一直在尝试想更多的方法来向编译器提出这个建议,但没有得到任何结果。我能做些什么来解决这个问题?
void foo(float theta)
{
theta = (float)M_PI*theta/180.0f;
MyClass variable = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, cos(theta), -sin(theta), 0.0f,
0.0f, sin(theta), cos(theta), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
bob = variable;
}
谢谢
编辑:将其更改为此会使警告消失,但我仍然想知道问题出在哪里
float C = cos(theta), S = sin(theta);
MyClass variable = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, C, -S, 0.0f,
0.0f, S, C, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };