Operator in C: not greater and equal to.

27,370

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

Share:
27,370
Unknown
Author by

Unknown

Updated on July 09, 2022

Comments

  • Unknown
    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
      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
      Unknown over 11 years
      You're going to have to expand on that.
    • Lee Taylor
      Lee Taylor over 11 years
      Um, isn't that the same as if(f<i) ?
    • Fantastic Mr Fox
      Fantastic Mr Fox over 11 years
      @LeeTaylor Yep, that is the answer that everyone below has provided.
    • David Schwartz
      David Schwartz over 11 years
      You're in luck! C has a "not greater than or equal to" operator. It's called "less than".
    • Daniel Fischer
      Daniel Fischer over 11 years
      It'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
      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.
      Peter O. over 11 years
      @mah: Guess you're right. Unfortunately, I can't take back my vote to close.
  • wizzwizz4
    wizzwizz4 almost 7 years
    This is not correct, as it will be true for anyvariablename == 0 which is unwanted.
  • Sophie
    Sophie almost 5 years
    Please note that a < b is not the same as !(a >= b) for floating point types if either value was NaN.