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));
Run Code Online (Sandbox Code Playgroud)
该代码应该将对象逆时针旋转 90 度,它确实做到了,但_btm_left.imag()
返回的值非常接近 0 = 1.437949e-009,而我确实需要它为 0。
我已经尝试过setprecision()
,setw()
但似乎没有任何效果。有没有类似的方法或者我需要创建自己的方法来解决这个问题?
前面的答案中提到的“神奇的epsilon”实际上是由语言通过提供的
#include <limits>
std::numeric_limits<float>::epsilon();
Run Code Online (Sandbox Code Playgroud)
和
std::numeric_limits<double>::epsilon();
Run Code Online (Sandbox Code Playgroud)
这是“1 和可表示的大于 1 的最小值之间的差”