Class Math
From TrainzOnline
(Difference between revisions)
m (1 revision) |
m (→Related Methods: Add link to RandBool) |
||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
− | *[[TrainzScript | + | *[[TrainzScript Language Reference|API Hierarchy]] |
**Math | **Math | ||
<br> | <br> | ||
Line 84: | Line 84: | ||
==Related Methods== | ==Related Methods== | ||
− | TrainUtil.RandBool() | + | [[Class TrainUtil#RandBool|TrainUtil.RandBool()]] |
[[Class Str#ToInt|Str.ToInt()]] | [[Class Str#ToInt|Str.ToInt()]] | ||
Line 93: | Line 93: | ||
[[Class Str#UnpackFloat|Str.UnpackFloat()]] | [[Class Str#UnpackFloat|Str.UnpackFloat()]] | ||
− | |||
==Categories== | ==Categories== | ||
[[Category:Script Class]] | [[Category:Script Class]] |
Latest revision as of 00:50, 29 December 2020
- API Hierarchy
- Math
- Math is a static class proving mathematical utility functions.
- When used in game code these methods must be prefixed Math. to reference the class.
Contents |
[edit] Abs
public int Abs(int number)
- Parameters
- number = integer value to be processed.
- Returned Value
- The absolute value of number.
- Syntax
int answer = Math.Abs(-1); // returns 1 int answer = Math.Abs(1); // returns 1
- Notes
[edit] Fabs
public float Fabs(float number)
- Parameters
- number = floating point value to be processed.
- Returned Value
- The absolute value of number.
- Syntax
float answer = Math.Fabs(-1.0); // returns 1.0 float answer = Math.Fabs(1.0); // returns 1.0
- Notes
[edit] Fmax
public float Fmax(float number1, float number2)
- Parameters
- number1, number2 = floating point values to be compared.
- Returned Value
- The greater of the two parameters.
- Syntax
float answer = Math.Fmax(1.0,2.0); // returns 2.0
- Notes
[edit] Fmin
public float Fmin(float number1, float number2)
- Parameters
- number1, number2 = floating point values to be compared.
- Returned Value
- The lesser of the two parameters.
- Syntax
float answer = Math.Fmin(1.0,2.0); // returns 1.0
- Notes
[edit] Rand
public native int Rand(int lower, int upper)
public native float Rand(float lower, float upper)
public native float Rand(float lower, float upper)
- Parameters
- lower = minimum value to be returned (inclusive)
- upper = maximum value to be returned (exclusive)
- Returned Value
- A random floating point or integer value within the specified range.
- Syntax
int random = Math.Rand(1,10); // returns a random number between 1 and 9 (see below) float random = Math.Rand(1.0,10.0); // returns a random number between 1.0 and 9.9999999... (see below)
- Notes
- Rand operates on floating point numbers but if both parameters are integers it will return an integer result.
- If either parameter is a float then the result will also be a float.
- The lower bound is inclusive and is therefore included in the set of possible return values.
- The upper bound is exclusive and is never included.
- In the case of an integer result the returned value is rounded down to an integral value. Because of this the call Math.Rand(1,10) will return a result between 1 and 9.
[edit] Sqrt
public native float Sqrt(float number)
- Parameters
- number = floating point value to find the square root of.
- Returned Value
- The square root of the parameter.
- Syntax
float root = Math.Sqrt(64.0); // returns 8.0
- Notes