Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mathf.Pow return wrong value??

Discussion in 'Scripting' started by Rafael8661, Jan 21, 2016.

  1. Rafael8661

    Rafael8661

    Joined:
    Jan 21, 2016
    Posts:
    4
    Hi guys,
    I'm try use Mathf.Pow method but maybe I don't know how it's realy work...
    Let's go, it's my debug code:
    Code (CSharp):
    1.  Debug.Log ("Acceleration Y:  " + Input.acceleration.y + "  Result:  " + Mathf.Pow(Input.acceleration.y, 0) + "\nAccelerationX:  " + Input.acceleration.x + "  Result:  " + Mathf.Pow(Input.acceleration.x , 0));
    2.  
    Ok, it's will get acceleration value and power of 0, right?
    So, assuming than Y value is -0.875, -0.875 to the power of 0 is -1, but the unity return 1! why??
    I'm forgetting something ??
    Look this real output:
    Code (CSharp):
    1. Acceleration Y:  -0.2080078  Result:  1
    2. Acceleration X:  -0.08300781  Result:  1
    Unity return 1 but it's should be -1.
    look this one:
    Code (CSharp):
    1. Acceleration Y:  0.01171875  Result:  1
    2. Acceleration X:  0.1259766  Result:  1
    This one is right, it's only work with positive number or I'm crazy? :/
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Looks like you're just overlooking math: anything to the zero power is 1, even negative numbers. :D
     
  3. Rafael8661

    Rafael8661

    Joined:
    Jan 21, 2016
    Posts:
    4
    Are you sure?
    Look:
     
  4. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    Look carefully at the brackets in your screenshot.
     
  5. Rafael8661

    Rafael8661

    Joined:
    Jan 21, 2016
    Posts:
    4
    Wow, I made a miss... :oops:
    Seemingly I ignore it, for make this in Google and my smartphone calculator is need a brackets in negative sign, such as (-3) ^ 0, and in unity not.
    Sory for it, I am very embarrassed. :oops:
     
  6. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
  7. Rafael8661

    Rafael8661

    Joined:
    Jan 21, 2016
    Posts:
    4