# Lua/Math Functions

< Lua

Here is a list of some useful math functions from Serious Engine which can be used in Lua scripts.

```  * mthAbsF(x) - Returns the absolute value of number x.

* mthSgnF(x) - Returns sign of a number (-1/0/+1 for x<0/x=0/x>0).

* mthFloorF(x) - Returns the floor (first integer lower or equal to) of number x.
* mthFracF(x) - Returns fractional part of a floating point number x.
* mthCeilF(x) - Returns the ceiling (first integer higher or equal to) of number x.
* mthRoundF(x) - Returns the nearest integer of number x.

* mthMaxF(x,y) - Returns the maximum of two numbers x and y.
* mthMinF(x,y) - Returns the minimum of two numbers x and y.

* mthClampDnF(x, downLimit) - Returns the value of x clamped down to the downLimit.
* mthClampUpF(x, upLimit) - Returns the value of x clamped up to the upLimit.
* mthClampF(x, downLimit, upLimit) - Returns the value of x clamped to the interval defined with downLimit and upLimit.
```
```  * mthSinF(x) - Returns the value of Sine function of angle x expressed in radians.
* mthCosF(x) - Returns the value of Cosine function of angle x expressed in radians.
* mthTanF(x) - Returns the value of Tangent function of angle x expressed in radians.

* mthASinF(x) - Returns the value of Arcus Sine function of value x, in radians.
* mthACosF(x) - Returns the value of Arcus Cosine function of value x, in radians.
* mthATanF(x) - Returns the value of Arcus Tangent function of value x, in radians.
```
```  * mthSqrtF(x) - Returns the square root of a positive number x.
* mthSafeSqrt(x) - Returns the square root of a number x (0 or the number is negative).
```
```  * mthLogEF(x) - Returns natural logarithm of a number x.
* mthLog10F(x) - Returns decimal logarithm of a number x.
* mthLog2F(x) - Returns base 2 logarithm of a number x.
* mthLogAF(b, x) - Returns base b logarithm of a number x.

* mthPow2F(x) - Returns 2 to the x-th power.
* mthPow10F(x) - Returns 10 to the x-th power.
* mthPowEF(x) - Returns E to the x-th power.
```
```  * mthDegToRad(x) - Converts angle x from degrees to radians.
```  * mthRndF() - Returns a random number in range 0.0 - 1.0 range.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5353489,"math_prob":0.9986945,"size":2172,"snap":"2019-51-2020-05","text_gpt3_token_len":655,"char_repetition_ratio":0.26891145,"word_repetition_ratio":0.18508998,"special_character_ratio":0.27348065,"punctuation_ratio":0.10047847,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99862313,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-22T23:27:53Z\",\"WARC-Record-ID\":\"<urn:uuid:4070a43b-2c99-4c46-a922-6610bfb04403>\",\"Content-Length\":\"14518\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6f063c31-e705-4b4b-a951-d865f6607726>\",\"WARC-Concurrent-To\":\"<urn:uuid:f038eed2-134e-4e7c-878a-974caa2566aa>\",\"WARC-IP-Address\":\"64.90.53.132\",\"WARC-Target-URI\":\"http://www.serioussam.com/wiki/index.php?title=Lua/Math_Functions\",\"WARC-Payload-Digest\":\"sha1:G2MX7G2DK4Z7D275WAZGRUHTC5RGM5ZR\",\"WARC-Block-Digest\":\"sha1:6VJOGQMVH4ALAA5DRFI2HZZ6F4DQ7XFR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250607596.34_warc_CC-MAIN-20200122221541-20200123010541-00457.warc.gz\"}"}