zscript-doc/api/global/func/Math.md

125 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2018-12-29 16:05:19 -08:00
# Math
2019-04-10 05:41:08 -07:00
These are all of the math functions provided to ZScript. These are available in
all contexts. Note that all angles are in degrees.
2018-12-29 16:05:19 -08:00
```
Type Abs(Type n);
2019-04-10 05:41:08 -07:00
double ACos(double n);
double ASin(double n);
double ATan(double n);
2018-12-29 16:05:19 -08:00
double ATan2(double y, double x);
uint BAM(double angle);
2019-04-10 05:41:08 -07:00
double Ceil(double n);
2018-12-29 16:05:19 -08:00
Type Clamp(Type n, Type minimum, Type maximum);
2019-04-10 05:41:08 -07:00
double Cos(double n);
double CosH(double n);
double Exp(double n);
double Floor(double n);
double Log(double n);
double Log10(double n);
2018-12-29 16:05:19 -08:00
Type Max(Type n, Type maximum);
Type Min(Type n, Type minimum);
2019-04-10 05:41:08 -07:00
double Sin(double n);
double SinH(double n);
double Sqrt(double n);
double Tan(double n);
double TanH(double n);
2018-12-29 16:05:19 -08:00
double VectorAngle(double x, double y);
```
2019-08-14 03:31:41 -07:00
### `Abs`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns `|n|` (absolute of `n`.)
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `ACos`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the arc-cosine of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `ASin`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the arc-sine of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `ATan`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the arc-tangent of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `ATan2`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns the arc-tangent of `y / x` using the arguments' signs to determine the
correct quadrant.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `BAM`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns a byte angle of `angle` (`degrees * (0x40000000 / 90.0)`.)
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `Ceil`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the integral portion of `n`, rounded up.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Clamp`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns `n` if `n` is more than `minimum` and less than `maximum`, or either of
those values if it is not.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `Cos`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the cosine of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `CosH`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the hyperbolic cosine of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Exp`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns euler's number raised to the power `n`. Note that you probably want
instead the `**` binary operator, as in `a ** b`, since euler's number is
generally not a very useful constant when programming games.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Floor`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the integral portion of `n`, rounded down.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Log`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the natural (base of euler's number) logarithm of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Log10`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the common (base 10) logarithm of `n`. Note that this is useful for
instance when calculating the number of decimal digits in a number.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Max`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns `n` if `n` is less than `maximum`, or `maximum`.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `Min`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns `n` if `n` is more than `minimum`, or `minimum`.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `Sin`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the sine of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `SinH`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the hyperbolic sine of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Sqrt`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the square root of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `Tan`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the tangent of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `TanH`
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
Returns the hyperbolic tangent of `n`.
2019-04-10 05:41:08 -07:00
2019-08-14 03:31:41 -07:00
### `VectorAngle`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Same as `ATan2`, but with arguments reversed.
2018-12-29 16:05:19 -08:00
<!-- EOF -->