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 3 months

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