ROBOTC 4.X has a powerful collection of math functions that can be used to create and solve complex mathematical formulas.
| float abs(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a positive floating point decimal value. | float |
| input | The number to take the absolute value of. | (can be: int, long, short, float) |
|
Code Example:
|
| float acos(const float Cosine) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value. | float |
| Cosine | The number to take the arc-cosine of (in radians). | float |
|
Code Example:
|
| float asin(const float Sine) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| Sine | The number to take the arc-sine of (in radians). | float |
|
Code Example:
|
| float atan(const float Tangent) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| Tangent | The number to take the arc-tangent of (in radians). | float |
|
Code Example:
|
| float atof(string str) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| str | The string to convert to a float. | string |
|
Code Example:
|
| long atoi(string str) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a long integer value | long |
| str | The string to convert to a long. | string |
|
Code Example:
|
| float ceil(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| input | The number to find the ceiling of (round up to nearest integer) | float |
|
Code Example:
|
| float cos(const float fRadians) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| fRadians | The number to take the cosine of (in radians). | float |
|
Code Example:
|
| float cosDegrees(const float fDegrees) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| fDegrees | The number to take the cosine of (in degrees). | float |
|
Code Example:
|
| float degreesToRadians(const float fDegrees) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| fDegrees | The number of degrees to convert into radians. | int |
|
Code Example:
|
| float exp(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| input | The floating point number to raise the constant 'e' to. | float |
|
Code Example:
|
| float floor(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| input | The floating point number to take the floor value of (round down to nearest integer) | float |
|
Code Example:
|
| float log(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| input | The floating point number to take the natural logarithm of. | float |
|
Code Example:
|
| float log10(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| input | The floating point number to take the base-10 logarithm of. | float |
|
Code Example:
|
| const float PI | ||
|---|---|---|
| Variable Name | Range of Values | Data Type |
| PI | 3.14159265358979323846264338327950288419716939937510 | float |
|
Code Example:
|
| float pow(const float base, const float exponent) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| base | The floating point base to raise to the power of 'power'. | float |
| exponent | The floating point exponent to raise 'base' to. | float |
|
Code Example:
|
| short radiansToDegrees(const float fRadians) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a short integer value. | short |
| fRadians | The number of radians to convert into degrees. | float |
|
Code Example:
|
| word rand() | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a word type integer value | word |
A typical way to generate pseudo-random numbers in a determined range using rand is to use the modulo of the returned value by the range span and add the initial value of the range:
( value % 100 ) is in the range 0 to 99
Notice though that this modulo operation does not generate a truly uniformly distributed random number in the span (since in most cases lower numbers are slightly more likely), but it is generally a good approximation for short spans.
|
Code Example:
|
| long randLong() | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a long type integer | long |
A typical way to generate pseudo-random numbers in a determined range using rand is to use the modulo of the returned value by the range span and add the initial value of the range:
( value % 100 ) is in the range 0 to 99
Notice though that this modulo operation does not generate a truly uniformly distributed random number in the span (since in most cases lower numbers are slightly more likely), but it is generally a good approximation for short spans.
|
Code Example:
|
| short sgn(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a short integer value | short |
| input | The number to test the sign of | float |
|
Code Example:
|
| float sin(const float fRadians) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| fRadians | The number to take the sine of (in radians). | float |
|
Code Example:
|
| float sinDegrees(const float fDegrees) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| fDegrees | The number to take the sine of (in degrees). | float |
|
Code Example:
|
| void srand(const long nSeedValue) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns no value | void |
| nSeedValue | The seed for a pseudo-random number generator, rand() or randlong() | long |
For every different seed value used in a call to srand, the pseudo-random number generator can be expected to generate a different succession of results in the subsequent calls to rand.
|
Code Example:
|
| float sqrt(const float input) | ||
|---|---|---|
| Parameter | Explanation | Data Type |
| Return Type | The function returns a floating point decimal value | float |
| input | The number to take the square-root of. | float |
|
Code Example:
|