I write this piece of code and processing gives me an error, please, help!

edited November 2013 in Questions about Code
      if ( (-0.125) <= (angle) <= (0.125) ||
      (0.375) <= (angle) <= (0.625) || 
      (0.875) <= (angle) <= (1.125) ||
      (1.375) <= (angle) <= (1.625)) {
        minDist = 40*windows[i].q + 40*q;
      }
      else {
        minDist = 40*windows[i].q*sqrt(2) + 40*q*sqrt(2);
      }

After compiling program gives me an error: "The operator <= is undefined for the argument type(s) boolean, float" Same if I change <= to <. I also tried to replace numbers with variables, nothing helps.

What am I doing wrong?

Answers

  • Answer ✓

    you can't say (-0.125) <= (angle) <= (0.125)

    you need

    (-0.125) <= (angle) &&

    (angle) <= (0.125)

  • Thank you, got if a sec before your answer. I'm such a moron :D

  • Answer ✓

    so you have to do it all step by step.

    you could write a function

    isValueInBetween (angle, -0.125, -0.125);

    to make the code shorter

    the function could look like

    boolean isValueInBetween (float test, float minBorder, float maxBorder) {
    return (minBorder <= test) && (test <= maxBorder) ;
    }
    
Sign In or Register to comment.