简体   繁体   English

零大于或等于零将得出false

[英]zero is greater than or equal to zero evaluates to false

i = 0;
if(0 <= i <= 0) 

this returns false. 这返回false。

I don't understand this at all. 我一点都不明白。 Watch window I also tried making the statement read (0 <= i && i <= 0) when I test them individually 0 <= i returns false while i <= 0 returns true. 在监视窗口中,当我分别测试它们时,我还尝试将语句读取为(0 <= i && i <= 0) 0 <= i返回false,而i <= 0返回true。 they both should be true. 他们俩都应该是真的。 I'm not sure if this is a precision thing but I wouldn't think so since I'm hard coding the values in. Please help me understand this fundamental problem. 我不确定这是否精确,但是由于要对值进行硬编码,因此我不认为这是精确的。请帮助我理解这个基本问题。

If it helps I am trying to evaluate if a point is on a line by getting the intersection point and then checking if it's between the x and y start point and end point. 如果有帮助,我尝试通过获取相交点来评估点是否在直线上,然后检查它是否在x和y起点和终点之间。 this becomes a problem when I am trying to check when x or y is on its axis then you run into the problem of checking if 0 is between or equal to 0 and 0. Which it is so it would fall on the line. 当我尝试检查x或y在其轴上时,这将成为一个问题,然后您会遇到检查0是否在0和0之间或等于0与0之间的问题。

Chaining of relational operators is not possible (to produce a valid result as per the expectation), you need to write separate instruction to verify each condition. 关系运算符的链接是不可能的(根据期望产生有效的结果),您需要编写单独的指令来验证每个条件。

Due to the absence of explicit parenthesis and LTR association , a statement like 由于缺乏明确的括号和LTR关联

  if(0 <= i <= 0) 

is evaluated as 被评估为

  if( (0 <= i) <= 0) 

which boils down to 归结为

  if ( 1 <= 0)

which produces a 0, (FALSE). 产生0(FALSE)。

That said, the claim pertaining to 也就是说,与

I also tried making the statement read (0 <= i && i <= 0) when I test them individually 0 <= i returns false while i <= 0 returns true. 当我分别测试它们时,我还尝试将语句读取为(0 <= i && i <= 0) 0 <= i返回false,而i <= 0返回true。 they both should be true 他们都应该是真的

is not correct, they both are true . 是不正确的, 它们都是真的 See for yourself 你自己看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM