如果声明没有执行

时间:2015-11-29 19:52:35

标签: c++ if-statement static const

我遇到if语句没有被执行的问题。下面的角是固定的,const。 现在我想要一个静态变量alphadrone从一个角移动到另一个角。

第一个'if'有效,第二个'if'无效。

LATLON_TO_CM是1.113195f 。我试图将f放在每个数字后面,使所有浮动,双重,语句不会被执行。 这不是逻辑,我将相同的数字放入两个变量(具有不同的名称但具有相同的数据类型)中,并且它不起作用。

const int32_t corner_1_X = 47.590000 * 1e3 * LATLON_TO_CM;
const int32_t corner_1_Y = 7.646000  * 1e3 * LATLON_TO_CM; //bigger
const int32_t corner_2_X = 47.590000 * 1e3 * LATLON_TO_CM;
const int32_t corner_2_Y = 7.644000  * 1e3 * LATLON_TO_CM; //smaller

static int32_t alphadroneXposition = corner_1_X;
static int32_t alphadroneYposition = corner_1_Y;

// if (corner_1_Y > corner_2_Y)
    // moveAlphadroneYneg(&alphadroneYposition);
if (alphadroneYposition > corner_2_Y)
    moveAlphadroneYneg(&alphadroneYposition);

1 个答案:

答案 0 :(得分:-1)

因此,出于某种原因,你的代码并没有说alphadroneYposition大于角位置,即使它有点大。我自己看了三次只是为了确认是的,第一个数字有点大。

alphadroneYposition = 7.646000 * 1e3

corner_2_Y = 7.644000 * 1e3

通常这是因为浮点精度和比较两个浮点数所导致的错误。在比较浮点数时,从s​​tackoverflow中查看相关主题。

What is the most effective way for float and double comparison?

希望这有帮助!