damn_T_T's blog

By damn_T_T, history, 5 years ago, In English

Here line 12 and 14 should output the same value (expected output 1)

But why when I call range(i,mn,mx) it outputs 0?

  • Vote: I like it
  • -14
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +8 Vote: I do not like it

you should write

#define range(i,mn,mx) (((i) >= mn) && ((i) <= mx)?1:0)

instead of

#define range(i,mn,mx) ((i >= mn) && (i <= mx)?1:0)
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    why ?

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 2   Vote: I like it +8 Vote: I do not like it

      If you write #define range(i,mn,mx) ((i >= mn) && (i <= mx)?1:0) then range(x||y,0,1) will be like ((x||y >= mn) && (x||y <= mx)?1:0) => ((x||(y >= mn)) && (x||(y <= mx))?1:0)