Search Unity

No clue whats wrong here

Discussion in 'Scripting' started by MrSecretMansion, Mar 25, 2017.

  1. MrSecretMansion

    MrSecretMansion

    Joined:
    Nov 17, 2013
    Posts:
    113
    This code gives me this error;
    "CS0019 Operator '^' cannot be applied to operands of type 'float' and 'float'"
    I'm at a loss for what could be causing this. (Btw, all three of these variables are floats)

    sum1 = sum1 ^ nTwo;

    This code also gives the same error;
    sum2 = sum2 ^ (1/nOne);
     
    Last edited: Mar 25, 2017
  2. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    2,623
    When it says it can't use '^' on floats it means just that.

    You can't use that with floats.

    "^" is a bitwise operator. It can only be used shuffle bit data around. Unless you REALLY know what you're doing, try something else.
     
  3. MrSecretMansion

    MrSecretMansion

    Joined:
    Nov 17, 2013
    Posts:
    113
    Is there any alternative solution to this? Also, why is this a limitation, shouldn't it work if the float is whole from a mathematical perspective?
     
  4. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    2,623
  5. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    505
    What are you trying to do? Adjust bits? Raise to the power of?
     
  6. MrSecretMansion

    MrSecretMansion

    Joined:
    Nov 17, 2013
    Posts:
    113
    Figured it out, I use mathf.pow