# 4. The Math library¶

the math lib provides basic mathematic routines. The library mimics the C runtime library implementation.

## 4.1. Squirrel API¶

### 4.1.1. Global Symbols¶

`abs`(x)

returns the absolute value of x as an integer

`acos`(x)

returns the arccosine of x

`asin`(x)

returns the arcsine of x

`atan`(x)

returns the arctangent of x

`atan2`(x, y)

returns the arctangent of x/y

`ceil`(x)

returns a float value representing the smallest integer that is greater than or equal to x

`cos`(x)

returns the cosine of x

`exp`(x)

returns the exponential value of the float parameter x

`fabs`(x)

returns the absolute value of x as a float

`floor`(x)

returns a float value representing the largest integer that is less than or equal to x

`log`(x)

returns the natural logarithm of x

`log10`(x)

returns the logarithm base-10 of x

`pow`(x, y)

returns x raised to the power of y

`rand`()

returns a pseudorandom integer in the range 0 to RAND_MAX

`sin`(x)

rreturns the sine of x

`sqrt`(x)

returns the square root of x

`srand`(seed)

sets the starting point for generating a series of pseudorandom integers

`tan`(x)

returns the tangent of x

`RAND_MAX`

the maximum value that can be returned by the rand() function

`PI`

The numeric constant pi (3.141592) is the ratio of the circumference of a circle to its diameter

## 4.2. C API¶

SQRESULT `sqstd_register_mathlib`(HSQUIRRELVM v)
Parameters: v (HSQUIRRELVM) – the target VM an SQRESULT The function aspects a table on top of the stack where to register the global library functions.

initializes and register the math library in the given VM.