Cos(90)返回非常接近0的值,但是我需要0? [英] Cos(90) returning a value very close to 0, but I need 0?
问题描述
temp_x_btm_left的值= 0&temp_y_btm_left = 1;
The values for temp_x_btm_left = 0 & temp_y_btm_left=1;
angle = 90;
//Moving the bottom left coordinates
_btm_left.real() = (temp_x_btm_left * cos(angle*PI/180))
- (temp_y_btm_left * sin(angle*PI/180));
_btm_left.imag() = (temp_x_btm_left * sin(angle*PI/180))
+ (temp_y_btm_left * cos(angle*PI/180));
该代码应该将对象逆时针旋转90度,但 _btm_left.imag()
返回的值实际上接近0 = 1.437949e-009,而我确实需要它是0.
The code is supposed to rotate the object 90 degrees counter-clockwise, which it does but the _btm_left.imag()
returns a value really close to 0 = 1.437949e-009, and I really need it being 0.
我已经尝试过 setprecision()
和 setw()
,但这似乎没有任何效果.有什么方法可以解决此类问题吗?还是需要创建自己的方法来解决此问题?!
I've tried setprecision()
and setw()
but it doesn't seem to have any effect. Are there any methods for anything like this or do I need to create my own to solve this?!
推荐答案
只要| v1-v2 |<预定义的Delta,只需考虑v1 == v2.
As long as |v1-v2| < predefinedDelta, simply consider v1 == v2.
这篇关于Cos(90)返回非常接近0的值,但是我需要0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!