2025-09-04 08:38:35 +10:00
|
|
|
# Math library
|
|
|
|
|
|
|
|
|
|
This library adds extra math functions to Ground. Unlike the official math library, all these features are coded in pure Ground.
|
|
|
|
|
|
|
|
|
|
Please note that you cannot copy a single function from the package, as some functions rely on other functions in the library.
|
|
|
|
|
|
|
|
|
|
## Functions
|
|
|
|
|
|
|
|
|
|
### fun -double !sin -double &input
|
|
|
|
|
|
|
|
|
|
Gets the sin of input.
|
|
|
|
|
|
|
|
|
|
### fun -double !cos -double &input
|
|
|
|
|
|
|
|
|
|
Gets the cos of input.
|
|
|
|
|
|
|
|
|
|
### fun -double !tan -double &input
|
|
|
|
|
|
|
|
|
|
Gets the tan of input.
|
|
|
|
|
|
2025-09-18 11:00:00 +10:00
|
|
|
### fun -double !asin -double &input
|
|
|
|
|
|
|
|
|
|
Finds the angle *x* in the range [-pi/2, pi/2] such that sin(x) equals the input.
|
|
|
|
|
|
|
|
|
|
### fun -double !acos -double &input
|
|
|
|
|
|
|
|
|
|
Finds the angle *x* in the range [0, pi] such that cos(x) equals the input.
|
|
|
|
|
|
|
|
|
|
### fun -double !atan -double &input
|
|
|
|
|
|
|
|
|
|
Finds the angle *x* in the range [-pi/2, pi/2] such that tan(x) equals the input.
|
|
|
|
|
|
|
|
|
|
### fun -double !atan2 -double &y -double &x
|
|
|
|
|
|
|
|
|
|
Finds the angle in the range (-pi, pi] between the positive x axis and the point (x,y). This is equivalent to atan(y/x) for positive values of x.
|
|
|
|
|
|
2025-09-04 08:38:35 +10:00
|
|
|
### fun -double !intexp -double &base -int &power
|
|
|
|
|
|
|
|
|
|
Returns base^power, for positive integer values of power. Returns 1 if power is non-positive (and thus is inaccurate for negative values of power).
|
|
|
|
|
|
2025-09-17 17:58:06 +10:00
|
|
|
### fun -double !exp -double &input
|
|
|
|
|
|
|
|
|
|
Finds exp($input), where exp(x)=e^x, e is Euler's number = 2.718281828...
|
|
|
|
|
|
|
|
|
|
### fun -double !ln -double &in
|
|
|
|
|
|
|
|
|
|
Finds the natural log (log_e) of $input, i.e. finds x such that e^x = $input, e is Euler's number = 2.718281828...
|
|
|
|
|
|
2025-09-04 08:38:35 +10:00
|
|
|
### fun -double !sqrt -double &input
|
|
|
|
|
|
|
|
|
|
Returns the positive value *x* that satisfies x^2 = input. Throws an error if input is negative.
|
|
|
|
|
|
|
|
|
|
### fun -double !mod -double &in -double &modulus
|
|
|
|
|
|
|
|
|
|
Returns *n* such that *n* is congruent to the input modulo $modulus, where *n* is at least 0 and less than $modulus.
|
|
|
|
|
|
2025-09-17 17:58:06 +10:00
|
|
|
### fun -double !abs -double &in
|
|
|
|
|
|
|
|
|
|
Returns the absolute value of *n*.
|
|
|
|
|
|
2025-09-04 08:38:35 +10:00
|
|
|
### fun -double !random -int &seed
|
|
|
|
|
|
|
|
|
|
Gets a random double in the domain [0,1), using a LCG. A seed is required.
|
|
|
|
|
|
|
|
|
|
### fun -double !pi
|
|
|
|
|
|
|
|
|
|
Returns pi to the maximum accuracy that doubles can store.
|
|
|
|
|
|
|
|
|
|
### fun -double !itod -int &input
|
|
|
|
|
|
|
|
|
|
Returns the input as a double.
|
|
|
|
|
|
|
|
|
|
### fun -int !dtoi -double &input
|
|
|
|
|
|
|
|
|
|
Returns the input as an integer.
|