Operator in C: not greater and equal to.
Solution 1
Just change it to (f < i)
which is !(f >= i)
.
Note: this is not the case if either f
or i
is NaN
. This is because f >= i
will evaluate to false
if either is NaN
leading to !(f >= i)
evaluating to true
where f < i
evaluates to false
.
Solution 2
You want to do: if (!(f>=0))...
Specific to what you're doing, using <
makes more sense. My suggestion here is just for a generic means of reversing polarity on any if statement.
Solution 3
Not greater than or equal to is equivalent to less than.
Solution 4
Use the aliter i.e instead of !>
think in reverse and use f<i
and you cant use ! for more than one operator i.e !+= is not valid
Unknown
Updated on July 09, 2022Comments
-
Unknown almost 2 years
Just a fast question:
I'm trying to test if a variable is not greater than or equal to another variable.
I have it coded as such:
if (f!>=i){ print ("True");}
but my c compiler won't recognize it. I can't find it online, is it possible?
-
chris over 11 years! is a unary operator. It has to be applied to one thing, so think of what that one thing should be.
-
Unknown over 11 yearsYou're going to have to expand on that.
-
Lee Taylor over 11 yearsUm, isn't that the same as
if(f<i)
? -
Fantastic Mr Fox over 11 years@LeeTaylor Yep, that is the answer that everyone below has provided.
-
David Schwartz over 11 yearsYou're in luck! C has a "not greater than or equal to" operator. It's called "less than".
-
Daniel Fischer over 11 yearsIt's unlikely to be important for your use case, but the pedant in me is compelled to note that
f < i
is not equivalent to!(f >= i)
if a NaN is involved. A comparison with a NaN always returns 0 (false). -
mah over 11 years@PeterO. What does this question have to do with the comma operator? Perhaps you mis-linked the possible duplicate?
-
Peter O. over 11 years@mah: Guess you're right. Unfortunately, I can't take back my vote to close.
-
-
wizzwizz4 almost 7 yearsThis is not correct, as it will be true for
anyvariablename == 0
which is unwanted. -
Sophie almost 5 yearsPlease note that
a < b
is not the same as!(a >= b)
for floating point types if either value was NaN.