Unknown
Unknown

Reputation: 676

Operator in C: not greater and equal to.

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?

Upvotes: 6

Views: 41506

Answers (5)

Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

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.

Upvotes: 12

saikiran reddy
saikiran reddy

Reputation: 11

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

Upvotes: 1

user7344668
user7344668

Reputation: 49

You can write it like so:

if(!(anyvariablename<0))

Upvotes: -1

Dan
Dan

Reputation: 13160

Not greater than or equal to is equivalent to less than.

Upvotes: 2

mah
mah

Reputation: 39807

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.

Upvotes: 5

Related Questions