Add packages/math/math.md

This commit is contained in:
2025-09-04 08:38:35 +10:00
parent 5515525413
commit d71813fd56

47
packages/math/math.md Normal file
View File

@@ -0,0 +1,47 @@
# 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.
### 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).
### 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.
### 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.