Aller au contenu

Photo

NWScript Math. taking the cube root....


  • Veuillez vous connecter pour répondre
3 réponses à ce sujet

#1
henesua

henesua
  • Members
  • 3 883 messages
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? 

#2
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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 .


#3
henesua

henesua
  • Members
  • 3 883 messages
Ah.... I did not realize you could do that. Thats great, thanks.

#4
AndarianTD

AndarianTD
  • Members
  • 706 messages
Didn't realize nwscript had a pow function. Learn something new every day. :)