Author Topic: NWScript Math. taking the cube root....  (Read 320 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NWScript Math. taking the cube root....
« on: July 26, 2012, 05:03:25 am »


               Has anyone found a method to take the cubed root of something? (root 3)
I see a square root function, but no other way to handle a larger root. Root 3 is really handy as it allows the kind of curve I want for a function I am running.

Anyone skilled enough in math to be able to help me cube root a number using a custom function? 
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NWScript Math. taking the cube root....
« Reply #1 on: July 26, 2012, 05:41:22 am »


               Use the Pow function:

// Maths operation: fValue is raised to the power of fExponent
// * Returns zero if fValue ==0 and fExponent <0
float pow(float fValue, float fExponent)


The Cube root of  X is the same thing as X to the 1/3 Power.   So to get the cube root of X you would use.

Pow ( x, 1.0/3.0);
               
               

               


                     Modifié par Lightfoot8, 26 juillet 2012 - 04:42 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NWScript Math. taking the cube root....
« Reply #2 on: July 26, 2012, 05:44:32 am »


               Ah.... I did not realize you could do that. Thats great, thanks.
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
NWScript Math. taking the cube root....
« Reply #3 on: July 27, 2012, 04:55:56 am »


               Didn't realize nwscript had a pow function. Learn something new every day. '<img'>