Jump to content

Square Root Function


Xmlspy
 Share

Recommended Posts

Does anyone know if Leadwerks has a square root function for LUA?

 

EDIT:

sqrt is highlighted in blue, but it doesn't work.

 

The reason I want a square root function is to determine the distance between two points using xy positions and the good ol distance formula sqrt( (x2-x1)^2 + (y2-y1)^2 ). Since there is no square root function (that I have found) one workaround is to create two pivot points, give them the x and y positions of each point, then use pivotOne:GetDistance(pivotTwo).

Link to comment
Share on other sites

The functions in the link I provided are part of the lua language. The ones you see like, Math:Sqrt, are part of the Leadwerks library. Every language has some base functions/features they provide but then people can make libraries using that language. I'm not 100% sure why Josh felt the need to duplicate some of these built in functions that Lua already had.

Link to comment
Share on other sites

That's a good point Naughty Alien, because from a machine standpoint, a Taylor series is usually used to compute more complex mathematical functions (not too sure about square root, but I would guess so).

 

Would it be much slower for Lua? I would suspect that since it is a built-in Lua function, the interpretation would call the machine code for computing a square root. I feel that the interpretation overhead wouldn't come close to the calculation time. I might be wrong about this though, I just like to learn about these things! biggrin.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...