kitten/math

This module specifies a few simple mathematical functions for easy access in game development.

Honestly, I have no idea why these are not in the standard library.

Constants

pub const pi: Float

The constant pi, accurate to 10 decimal places.

Functions

pub fn atan2(y: Float, x: Float) -> Float

The arctangent function. Note that y is the first argument.

pub fn cos(x: Float) -> Float

The cosine function.

pub fn deg_to_rad(t: Float) -> Float

Converts the given angle in degrees to radians. The result is guaranteed to fall between 0 and 2pi.

pub fn lerp(a: Float, b: Float, p: Float) -> Float

Linearly interpolates between two numbers. Think of the result as the number 100 * p percent of the way between a and b.

Example:

math.lerp(10.0, 20.0, 0.3)
// -> 13.0
pub fn rad_to_deg(t: Float) -> Float

Converts the given angle in radians to degrees. The result is guaranteed to fall between 0 and 360.

pub fn sign(a: Float) -> Float

Returns 1.0 for positive numbers, -1.0 for negative numbers and 0.0 for 0.0.

Examples:

math.sign(-22.8)
// -> -1.0

math.sign(0.0)
// -> 0.0
pub fn sin(x: Float) -> Float

The sine function.

Search Document