# Math Functions

Here is a list of all the math functions and variables available to you in Terra. These can be used anywhere you have access to a function

## Variables

Here is a list of all the variables you have access to for all equations

### seed

The seed variables holds the current world seed. This can be passed to the `rand` function, which requires a seed.

### x

The current x coordinate.

### y

The current y coordinate.
Note: this variable does not exist for functions with 2d noise.

### z

The current z coordinate.

## Functions

### sin Returns the trigonometric sine of an angle.

Special cases:

• If the argument is NaN or an infinity, then the result is `NaN`.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Assume this works the same as the Java Math#sin function.

### cos Returns the trigonometric cosine of an angle.

Special cases:

• If the argument is NaN or an infinity, then the result is `NaN`.

Assume this works the same as the Java Math#cos function.

### tan Returns the trigonometric tangent of an angle.

Special cases:

• If the argument is NaN or an infinity, then the result is `NaN`.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Assume this works the same as the Java Math#tan function.

### sinh Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be `(ex - e-x)/2` where e is Euler's number.

Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is infinite, then the result is an infinity with the same sign as the argument.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Assume this works the same as the Java Math#sinh function.

### cosh Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be `(ex + e-x)/2` where `e` is Euler's number.

Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is infinite, then the result is positive infinity.
• If the argument is zero, then the result is `1.0`.

Assume this works the same as the Java Math#cosh function.

### tanh Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be `(ex - e-x)/(ex + e-x)`, in other words, `sinh(x)/cosh(x)`. Note that the absolute value of the exact tanh is always less than 1.

Special cases:

• If the argument is NaN, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.
• If the argument is positive infinity, then the result is +1.0.
• If the argument is negative infinity, then the result is -1.0.

Assume this works the same as the Java Math#tanh function.

### asin Returns the arc sine of a value; the returned angle is in the range `-pi/2` through `pi/2`.

Special cases:

• If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Assume this works the same as the Java Math#asin function.

### acos Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

Special case:

• If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

Assume this works the same as the Java Math#acos function.

### atan Returns the arc tangent of a value; the returned angle is in the range `-pi/2` through `pi/2`.

Special cases:

• If the argument is NaN, then the result is `NaN`.
• If the argument is zero, then the result is a zero with the same sign as the argument.

Assume this works the same as the Java Math#atan function.

### atan2 Returns the angle theta from the conversion of rectangular coordinates `(x, y)` to polar coordinates `(r, theta)`. This method computes the phase theta by computing an arc tangent of `y/x` in the range of `-pi` to `pi`.

Special cases:

• If either argument is NaN, then the result is NaN.
• If the first argument is positive zero and the second argument is positive, or the first argument is positive and finite and the second argument is positive infinity, then the result is positive zero.
• If the first argument is negative zero and the second argument is positive, or the first argument is negative and finite and the second argument is positive infinity, then the result is negative zero.
• If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the double value closest to `pi`.
• If the first argument is negative zero and the second argument is negative, or the first argument is negative and finite and the second argument is negative infinity, then the result is the double value closest to `-pi`.
• If the first argument is positive and the second argument is positive zero or negative zero, or the first argument is positive infinity and the second argument is finite, then the result is the double value closest to `pi/2`.
• If the first argument is negative and the second argument is positive zero or negative zero, or the first argument is negative infinity and the second argument is finite, then the result is the double value closest to `-pi/2`.
• If both arguments are positive infinity, then the result is the double value closest to `pi/4`.
• If the first argument is positive infinity and the second argument is negative infinity, then the result is the double value closest to `3*pi/4`.
• If the first argument is negative infinity and the second argument is positive infinity, then the result is the double value closest to `-pi/4`.
• If both arguments are negative infinity, then the result is the double value closest to `-3*pi/4.`

Assume this works the same as the Java Math#atan2 function.

### deg

Converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.
This is the same as doing `x * 180 / 3.14159...`.

Assume this works the same as the Java Math#atan2 function.

Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.
This is the same as doing `x * 3.15159... / 180`.

Assume this works the same as the Java Math#atan2 function.

### abs

Returns the absolute value of a float value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

Special cases:

• If the argument is positive zero or negative zero, the result is positive zero.
• If the argument is infinite, the result is positive infinity.
• If the argument is NaN, the result is NaN.

Assume this works the same as the Java Math#atan2 function.

### round Returns the closest integer to the argument, with ties rounding to positive infinity.

Special cases:

• If the argument is `NaN`, the result is `0`.
• If the argument is negative infinity or any value less than or equal to the value of `Long.MIN_VALUE`, the result is equal to the value of `Long.MIN_VALUE`.
• If the argument is positive infinity or any value greater than or equal to the value of `Long.MAX_VALUE`, the result is equal to the value of `Long.MAX_VALUE`.

Assume this works the same as the Java Math#atan2 function.

### ceil Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.

Special cases:

• If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
• If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
• If the argument value is less than zero but greater than -1.0, then the result is negative zero.

Note that the value of ceil(x) is exactly the value of -floor(-x).

Assume this works the same as the Java Math#atan2 function.

### floor

Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal to a mathematical integer.

Special cases:

• If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
• If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

### exp

Returns Euler's number e raised to the power of a value. Special cases:

• If the argument is NaN, the result is NaN.
• If the argument is positive infinity, then the result is positive infinity.
• If the argument is negative infinity, then the result is positive zero.