Use Cases Of These Math Functions?

Hello Developers! :wave:

I’m wondering what are the use cases of these math functions?

Because, I only see myself using math.huge(), math.random(), and math.rad(). I only use math.rad() for CFrame.Angles()

Any response it appreciated! :slightly_smiling_face:

1 Like

Hi!

The more I’m moving down your list, the more uses for each function I can count.
math.floor and math.ceil are closely related, and they are very basic. When do we need to round numbers? Most often when we are working with data, prices, distances or points, for example, when we have to display results, and so on.

math.huge() returns the highest possible number, which can be, for instance, used while working with BodyMovers, and we have to ensure that enough power is used to move the object, or conversely, hold it still.

math.random() returns pseudo-random numbers, which are used very commonly as well. This function saves you a lot of time.

Whenever we are working with coordinate frames and angles, which always involve trigonomentry, we need to use math.pi and sometimes math.rad(), which is a conversion method (degrees to radians). I can say that I don’t usually use math.deg(), because cases when I have to convert radians back to degrees are relatively rare.

As far as math.pow() goes, it is equivalent to x^y, but is most likely faster, because exponents are slower than multiplication.

math.abs() may not seem so common, but is basic and indispensable. Don’t forget about math.pi, which is often underrated, but is in fact everywhere.

I took quite some time today to write this post about math.pi and math.rad().


Lua math library doesn't have a single function that could be left out. It contains everything a developer could need to do more demanding calculations, assemble complex functions, or simply do easier tasks. Besides, lua originates from C++, which is one of the most capable languages I know.
4 Likes

Awesome! Thanks for clearing the confusion for me!!

1 Like