Difference between revisions of "Math"

From ROBOTC API Guide
Jump to: navigation, search
(cos)
(randLong)
 
(31 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| style="font-family:Verdana, Genega, sans-sarif; font-size:80%;color:gray;" width="100%" cellpadding="0%" cellspacing="0" border="0"
+
<yambe:breadcrumb self="Math">General|General Programming</yambe:breadcrumb>
|-
+
<br />
|
+
''[[Main_Page|Main]] >> [[NXT_Main|NXT]] >> [[NXT: Functions|Functions]] >> [[Math|Math]] ''
+
|-
+
|}
+
 
+
ROBOTC has a powerful collection of useful math functions for the NXT, TETRIX, and VEX CORTEX platforms. '''The RCX and VEX PIC platforms do not have enough memory to store these more advanced math functions.'''
+
 
+
  
----
+
ROBOTC has a powerful collection of useful math functions for the NXT, TETRIX, VEX CORTEX, and Arduino MEGA-based platforms. '''The RCX, VEX PIC and Arduino 328P-based platforms do not have enough memory to store these more advanced math functions or support floating point numbers.'''
 +
<br />
  
 +
{{tl|1|1}}
 +
<br />
  
 
== abs ==
 
== abs ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float abs(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">abs</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the absolute value of a number.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the absolute value of a number.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the absolute value of (can be: int, long, short, float).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the absolute value of (can be: int, long, short, float).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 39: Line 37:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== acos ==
 
== acos ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float acos(const float Cosine)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">acos</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">Cosine</span><span class="bigCodePunc">)</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the arc-cosine of a number in radians.
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the arc-cosine of a number in radians.
+
|
    
+
  {| class="parameterTable" cellpadding="5%" width="100%"
 
+
   ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
  ! Explanation
+
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''Cosine''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''Cosine''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the arc-cosine of (in radians).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the arc-cosine of (in radians).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 70: Line 70:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== asin ==
 
== asin ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float asin(const float Sine)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">asin</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">Sine</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the arc-sine of a number in radians.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the arc-sine of a number in radians.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''Sine''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''Sine''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the arc-sine of (in radians).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the arc-sine of (in radians).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 101: Line 103:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== atan ==
 
== atan ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float atan(const float Tangent)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">atan</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">Tangent</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the arc-tangent of a number in radians.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the arc-tangent of a number in radians.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''Tangent''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''Tangent''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the arc-tangent of (in radians).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the arc-tangent of (in radians).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 132: Line 136:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 
+
== atof ==
== ceil ==
+
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float ceil(const float input)'''
+
| class="functionType"|
 +
<span class="bigKeywordBI">float </span>
 +
<span class="bigKeywordB">atof</span>
 +
<span class="bigCodePunc">(</span>
 +
<span class="bigKeywordBI">string </span>
 +
<span class="bigCodeBasic">str</span>
 +
<span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the '''smallest integer''' value that is greater than or equal to 'input'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns a float representation of the string, <span class="codeBasic">str</span>.
    
+
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 +
  |-
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|''str''  
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|The string to convert to a float.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_string|string]]
 +
  |-
 +
  |}
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="ROBOTC">
 +
task main()
 +
{
 +
  string strPI = "3.14";    // string 'strPI' is set equal to "3.14"
 +
  float test = atof(strPI); // convert the string value of 'strPI' to a float and set 'test' to that number (3.14)
 +
   while(true);              // keep the ROBOTC debugger alive so we can see the result
 +
}
 +
</syntaxhighlight>
 +
  |-
 +
  |}
 +
|-
 +
|}
 +
<br />
  
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
== atoi ==
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
  ! Explanation
+
|-
 +
| class="functionType"|
 +
<span class="bigKeywordBI">long </span>
 +
<span class="bigKeywordB">atoi</span>
 +
<span class="bigCodePunc">(</span>
 +
<span class="bigKeywordBI">string </span>
 +
<span class="bigCodeBasic">str</span>
 +
<span class="bigCodePunc">)</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_long|long]]) Returns a long representation of the string, <span class="codeBasic">str</span>.
 +
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''str''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the ceiling value of.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The string to convert to a long.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_string|string]]
 
   |-
 
   |-
 
   |}
 
   |}
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="ROBOTC">
 +
task main()
 +
{
 +
  string strPI = "3.14";    // string 'strPI' is set equal to "3.14"
 +
  long test = atoi(strPI);  // convert the string value of 'strPI' to a long and set 'test' to that number (3)
 +
  while(true);              // keep the ROBOTC debugger alive so we can see the result
 +
}
 +
</syntaxhighlight>
 +
  |-
 +
  |}
 +
|-
 +
|}
 +
<br />
  
 
+
== ceil ==
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">ceil</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the '''smallest integer''' value that is greater than or equal to <span class="codeBasic">input</span>.
 +
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 +
  |-
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|The floating point number to take the ceiling value of.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 +
  |-
 +
  |}
 +
|-
 +
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 161: Line 251:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== cos ==
 
== cos ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float cos(const float fRadians)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">cos</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fRadians</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the cosine of a number of radians.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the cosine of a number of radians.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fRadians''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the cosine of (in radians).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the cosine of (in radians).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 191: Line 283:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 
== cosDegrees ==
 
== cosDegrees ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float cosDegrees(const float fDegrees)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">cosDegrees</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fDegrees</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the cosine of a number of degrees.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the cosine of a number of degrees.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fDegrees''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the cosine of (in degrees).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the cosine of (in degrees).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 220: Line 315:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 
== degreesToRadians ==
 
== degreesToRadians ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float degreesToRadians(const float fDegrees)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">degreesToRadians</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fDegrees</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the radian equivalent of 'fDegrees'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the radian equivalent of <span class="codeBasic">fDegrees</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fDegrees''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number of degrees to convert into radians.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number of degrees to convert into radians.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
Line 249: Line 347:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== exp ==
 
== exp ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float exp(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">exp</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the number 'e' rasied to the power of 'input'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the number 'e' rasied to the power of <span class="codeBasic">input</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to raise the constant 'e' to.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The floating point number to raise the constant 'e' to.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 279: Line 379:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 
== floor ==
 
== floor ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float floor(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">floor</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the '''largest integer''' value that is less than or equal to 'input'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the '''largest integer''' value that is less than or equal to <span class="codeBasic">input</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the floor value of.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The floating point number to take the floor value of.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 307: Line 410:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== log ==
 
== log ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float log(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">log</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the natural logarithm ''(ln)'' of 'input'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the natural logarithm ''(ln)'' of <span class="codeBasic">input</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the natural logarithm of.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The floating point number to take the natural logarithm of.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 336: Line 441:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== log10 ==
 
== log10 ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float log10(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">log10</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the base-10 logarithm of 'input'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the base-10 logarithm of <span class="codeBasic">input</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the base-10 logarithm of.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The floating point number to take the base-10 logarithm of.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 365: Line 472:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 +
== PI ==
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="variableType"| <span class="bigKeywordBI">const float </span><span class="bigKeywordB">PI </span><span class="bigCodePunc">= </span><span class="bigCodeStringsNums">3.14159265358979323846264338327950288419716939937510</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) The constant <span style="font-family: Trebuchet MS, sans-serif">&pi;</span>.
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="ROBOTC">
 +
float y = 0.0;                // create and set 'y' to 0.0
 +
float LCD_width = 100.0;      // create and set 'LCD_width' to 100.0 (width of NXT LCD in pixels)
 +
 +
nxtDrawLine(0, 31, 99, 31);  // draw a line across the center of the LCD
 +
 +
for(int x = 0; x < 100; x++)  // loop from 0 to 99
 +
{
 +
  y = sin(x * (2.0 * PI) / LCD_width) * 25; // calculate y-coordinate of pixel to draw
 +
  nxtSetPixel(x, y + 31);                  // draw pixel at (x, y+31)
 +
  wait1Msec(100);                          // wait 100 milliseconds
 +
}
 +
</syntaxhighlight>
 +
  |-
 +
  |}
 +
|-
 +
|}
 +
<br />
  
 
== pow ==
 
== pow ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float pow(const float base, const float exponent)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">pow</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">base</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">exponent</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns 'base' to the power of 'exponent'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns <span class="codeBasic">base</span> to the power of <span class="codeBasic">exponent</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''base''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''base''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point base to raise to the power of 'power'.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The floating point base to raise to the power of 'power'.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''exponent''  
 
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''exponent''  
 
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point exponent to raise 'base' to.
 
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point exponent to raise 'base' to.
 +
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 398: Line 537:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== radiansToDegrees ==
 
== radiansToDegrees ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''short radiansToDegrees(const float fRadians)'''
+
| class="functionType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">radiansToDegrees</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fRadians</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the degree equivalent of 'fRadians'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Returns the degree equivalent of <span class="codeBasic">fRadians</span>.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fRadians''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number of radians to convert into degrees.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number of radians to convert into degrees.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 428: Line 569:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 
+
== rand ==
== sgn ==
+
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''short sgn(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">word </span><span class="bigKeywordB">rand</span><span class="bigCodePunc">()</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns a value less than 0 if 'input' is negative, and a value greater than 0 if 'input is positive.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_word|word]]) Returns a pseudo-random integral number in the range 0 to at least 32,767 (depending on platform).
 
+
  
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
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:
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
 
   ! Explanation
+
( value % 100 ) is in the range 0 to 99
 +
( value % 100 + 1 ) is in the range 1 to 100
 +
( value % 30 + 1985 ) is in the range 1985 to 2014
 +
 
 +
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.
 +
|-
 +
|
 +
   {|
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   |<syntaxhighlight lang="ROBOTC">
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to test the sign of
+
task main()
 +
{
 +
  int min = -100;   // create int variable 'min' and set it to -100
 +
  int max = 100;    // create int variable 'max' and set it to 100
 +
    
 +
  srand(nSysTime);  // generate seed for rand() from current system time
 +
 
 +
  while(true)      // infinite loop:
 +
  {
 +
    motor[rightMotor] = (rand() % (max-min)) + min; // set 'rightMotor' to a random number in the range: [min, max]
 +
    motor[leftMotor]  = (rand() % (max-min)) + min; // set 'leftMotor' to a random number in the range: [min, max]
 +
    wait1Msec(500); // wait 500 milliseconds
 +
  }
 +
}
 +
</syntaxhighlight>
 
   |-
 
   |-
 
   |}
 
   |}
 +
|-
 +
|}
 +
<br />
  
 +
== randLong ==
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="functionType"| <span class="bigKeywordBI">long </span><span class="bigKeywordB">randLong</span><span class="bigCodePunc">()</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_long|long]]) Returns a pseudo-random integral number in the range 0 to at least 2,147,483,647 (depending on platform).
  
 +
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
 +
( value % 100 + 1 ) is in the range 1 to 100
 +
( value % 30 + 1985 ) is in the range 1985 to 2014
 +
 +
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.
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="ROBOTC">
 +
task main()
 +
{
 +
  long min = -100;  // create long variable 'min' and set it to -100
 +
  long max = 100;    // create long variable 'max' and set it to 100
 +
 
 +
  srand(nSysTime);  // generate seed for rand() from current system time
 +
 
 +
  while(true)      // infinite loop:
 +
  {
 +
    motor[rightMotor] = (randLong() % (max-min)) + min; // set 'rightMotor' to a random number in the range: [min, max]
 +
    motor[leftMotor]  = (randLong() % (max-min)) + min; // set 'leftMotor' to a random number in the range: [min, max]
 +
    wait1Msec(500); // wait 500 milliseconds
 +
  }
 +
}
 +
</syntaxhighlight>
 +
  |-
 +
  |}
 +
|-
 +
|}
 +
<br />
 +
 +
== sgn ==
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="functionType"| <span class="bigKeywordBI">short </span><span class="bigKeywordB">sgn</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]]) Returns a value less than 0 if <span class="codeBasic">input</span> is negative, and a value greater than 0 if <span class="codeBasic">input</span> is positive.
 +
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 +
  |-
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to test the sign of
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 +
  |-
 +
  |}
 +
|-
 +
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 459: Line 682:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== sin ==
 
== sin ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float sin(const float fRadians)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">sin</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fRadians</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the sine of a number of radians.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the sine of a number of radians.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fRadians''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the sine of (in radians).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the sine of (in radians).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 489: Line 714:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
 
== sinDegrees ==
 
== sinDegrees ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float sinDegrees(const float fDegrees)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">sinDegrees</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fDegrees</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the sine of a number of degrees.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the sine of a number of degrees.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fDegrees''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the sine of (in degrees).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the sine of (in degrees).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 518: Line 746:
 
|-
 
|-
 
|}
 
|}
 +
<br />
  
== sqrt ==
+
== srand ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float sqrt(const float input)'''
+
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">srand</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const long </span><span class="bigCodeBasic">nSeedValue</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the square-root of 'input'.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) The pseudo-random number generator is initialized using the argument passed as <span class="codeBasic">nSeedValue</span>.
 
+
  
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
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.
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
Two different initializations with the same seed, instructs the pseudo-random generator to generate the same succession of results for the subsequent calls to rand in both cases.
  ! Explanation
+
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''nSeedValue''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the square-root of.
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The seed for the pseudo-random number generator, <span class="codeBasic">rand</span><span class="codePunc">()</span>
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_long|long]]
 
   |-
 
   |-
 
   |}
 
   |}
 +
|-
 +
|
 +
  {|
 +
  |-
 +
  |<syntaxhighlight lang="ROBOTC">
 +
task main()
 +
{
 +
  int min = -100;  // create int variable 'min' and set it to -100
 +
  int max = 100;    // create int variable 'max' and set it to 100
 +
 
 +
  srand(nSysTime);  // generate seed for rand() from current system time
 +
 
 +
  while(true)      // infinite loop:
 +
  {
 +
    motor[rightMotor] = (rand() % (max-min)) + min; // set 'rightMotor' to a random number in the range: [min, max]
 +
    motor[leftMotor]  = (rand() % (max-min)) + min; // set 'leftMotor' to a random number in the range: [min, max]
 +
    wait1Msec(500); // wait 500 milliseconds
 +
  }
 +
}
 +
</syntaxhighlight>
 +
  |-
 +
  |}
 +
|-
 +
|}
 +
<br />
  
 
+
== sqrt ==
 +
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 +
|-
 +
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">sqrt</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">input</span><span class="bigCodePunc">)</span>
 +
|-
 +
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the square-root of <span class="codeBasic">input</span>.
 +
|-
 +
|
 +
  {| class="parameterTable" cellpadding="5%" width="100%"
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
 +
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 +
  |-
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|''input''
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the square-root of.
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 +
  |-
 +
  |}
 +
|-
 +
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 547: Line 825:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
<!-- == tan ==
 
<!-- == tan ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float tan(const float fRadians)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">tan</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fRadians</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the tangent of a number of radians.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the tangent of a number of radians.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fRadians''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the tangent of (in radians).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the tangent of (in radians).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 576: Line 856:
 
|-
 
|-
 
|}
 
|}
 
+
<br />
  
 
== tanDegrees ==
 
== tanDegrees ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float tanDegrees(const float fDegrees)'''
+
| class="functionType"| <span class="bigKeywordBI">float </span><span class="bigKeywordB">tanDegrees</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const float </span><span class="bigCodeBasic">fDegrees</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the tangent of a number of degrees.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_float|float]]) Returns the tangent of a number of degrees.
 
+
|-
 
+
|
{| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%"
+
  {| class="parameterTable" cellpadding="5%" width="100%"
  ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter
+
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Parameter
  ! Explanation
+
  ! width="60%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Explanation
 +
  ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees''  
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|''fDegrees''  
   | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the tangent of (in degrees).
+
   | style="border-style: solid; border-width: 1px 0px 0px 0px"|The number to take the tangent of (in degrees).
 +
  | style="border-style: solid; border-width: 1px 0px 0px 0px"|[[Data_Types#dataType_float|float]]
 
   |-
 
   |-
 
   |}
 
   |}
 
+
|-
 
+
|
 
   {|
 
   {|
 
   |-
 
   |-
Line 604: Line 886:
 
   |}
 
   |}
 
|-
 
|-
|} -->
+
|}
 +
<br /> -->

Latest revision as of 15:23, 18 May 2012


ROBOTC has a powerful collection of useful math functions for the NXT, TETRIX, VEX CORTEX, and Arduino MEGA-based platforms. The RCX, VEX PIC and Arduino 328P-based platforms do not have enough memory to store these more advanced math functions or support floating point numbers.

Color Key
Function:
Variable:


abs

float abs(const float input)
(float) Returns the absolute value of a number.
Parameter Explanation Data Type
input The number to take the absolute value of (can be: int, long, short, float). float
float G = -9.81;           // create a variable 'G' and set it equal to -9.81
float downForce = abs(G);  // create and set variable 'downForce' to the absolute value of 'G' (9.81)


acos

float acos(const float Cosine)
(float) Returns the arc-cosine of a number in radians.
Parameter Explanation Data Type
Cosine The number to take the arc-cosine of (in radians). float
float param = 0.5;                        // create and set floating point variable 'param' to 0.5
float result = acos(param) * 180.0 / PI;  // create floating point variable 'result' and
                                          // set it equal to the arc-cosine of 'param' in degrees (60)


asin

float asin(const float Sine)
(float) Returns the arc-sine of a number in radians.
Parameter Explanation Data Type
Sine The number to take the arc-sine of (in radians). float
float param = 0.5;                        // create and set floating point variable 'param' to 0.5
float result = asin(param) * 180.0 / PI;  // create floating point variable 'result' and
                                          // set it equal to the arc-sine of 'param' in degrees (30)


atan

float atan(const float Tangent)
(float) Returns the arc-tangent of a number in radians.
Parameter Explanation Data Type
Tangent The number to take the arc-tangent of (in radians). float
float param = 0.5;                        // create and set floating point variable 'param' to 0.5
float result = asin(param) * 180.0 / PI;  // create floating point variable 'result' and
                                          // set it equal to the arc-sine of 'param' in degrees (26.565)


atof

float atof ( string str )

(float) Returns a float representation of the string, str.
Parameter Explanation Data Type
str The string to convert to a float. string
task main()
{
  string strPI = "3.14";    // string 'strPI' is set equal to "3.14"
  float test = atof(strPI); // convert the string value of 'strPI' to a float and set 'test' to that number (3.14)
  while(true);              // keep the ROBOTC debugger alive so we can see the result
}


atoi

long atoi ( string str )

(long) Returns a long representation of the string, str.
Parameter Explanation Data Type
str The string to convert to a long. string
task main()
{
  string strPI = "3.14";    // string 'strPI' is set equal to "3.14"
  long test = atoi(strPI);  // convert the string value of 'strPI' to a long and set 'test' to that number (3)
  while(true);              // keep the ROBOTC debugger alive so we can see the result
}


ceil

float ceil(const float input)
(float) Returns the smallest integer value that is greater than or equal to input.
Parameter Explanation Data Type
input The floating point number to take the ceiling value of. float
float E = 2.72;           // create a variable 'E' and set it equal to 2.72
float ceiling = ceil(E);  // create and set variable 'ceiling' to the ceiling value of 'E' (3)


cos

float cos(const float fRadians)
(float) Returns the cosine of a number of radians.
Parameter Explanation Data Type
fRadians The number to take the cosine of (in radians). float
float result = cos(PI);  // create a floating point variable 'result' and 
                         // set it equal to the cosine of PI (-1)


cosDegrees

float cosDegrees(const float fDegrees)
(float) Returns the cosine of a number of degrees.
Parameter Explanation Data Type
fDegrees The number to take the cosine of (in degrees). float
float result = cosDegrees(180);  // create a floating point variable 'result' and
                                 // set it equal to the cosine of 180 degrees (-1)


degreesToRadians

float degreesToRadians(const float fDegrees)
(float) Returns the radian equivalent of fDegrees.
Parameter Explanation Data Type
fDegrees The number of degrees to convert into radians. float


float radiansPerDegree = degreesToRadians(1.0);  // create a floating point variable 'radiansPerDegree ' 
                                                 // and set it equal to the amount of radians in 1.0 degrees (0.017)


exp

float exp(const float input)
(float) Returns the number 'e' rasied to the power of input.
Parameter Explanation Data Type
input The floating point number to raise the constant 'e' to. float
float result = exp(4);  // create floating point variable 'result' and 
                        // set it equal to e raised to the 4th power (e^4 = 54.598)


floor

float floor(const float input)
(float) Returns the largest integer value that is less than or equal to input.
Parameter Explanation Data Type
input The floating point number to take the floor value of. float
float E = 2.72;              // create a variable 'E' and set it equal to 2.72
float floorValue = ceil(E);  // create and set variable 'floorValue' to the ceiling value of 'E' (2)


log

float log(const float input)
(float) Returns the natural logarithm (ln) of input.
Parameter Explanation Data Type
input The floating point number to take the natural logarithm of. float
float E = 2.72;     // create a variable 'E' and set it equal to 2.72
float ln = log(E);  // create and set variable 'ln' to the natural log of 'E' (1.00)


log10

float log10(const float input)
(float) Returns the base-10 logarithm of input.
Parameter Explanation Data Type
input The floating point number to take the base-10 logarithm of. float
float E = 2.72;            // create a variable 'E' and set it equal to 2.72
float logBTen = log10(E);  // create and set variable 'logBTen' to the base-10 log of 'E' (0.43)


PI

const float PI = 3.14159265358979323846264338327950288419716939937510
(float) The constant π.
float y = 0.0;                // create and set 'y' to 0.0
float LCD_width = 100.0;      // create and set 'LCD_width' to 100.0 (width of NXT LCD in pixels)
 
nxtDrawLine(0, 31, 99, 31);   // draw a line across the center of the LCD
 
for(int x = 0; x < 100; x++)  // loop from 0 to 99
{
  y = sin(x * (2.0 * PI) / LCD_width) * 25; // calculate y-coordinate of pixel to draw
  nxtSetPixel(x, y + 31);                   // draw pixel at (x, y+31)
  wait1Msec(100);                           // wait 100 milliseconds
}


pow

float pow(const float base, const float exponent)
(float) Returns base to the power of exponent.
Parameter Explanation Data Type
base The floating point base to raise to the power of 'power'. float
exponent The floating point exponent to raise 'base' to. float
float kilobyte = pow(10, 3);  // create floating point variable 'kilobyte' and
                              // set it equal to 10^3 or 1000


radiansToDegrees

short radiansToDegrees(const float fRadians)
(short) Returns the degree equivalent of fRadians.
Parameter Explanation Data Type
fRadians The number of radians to convert into degrees. float
float degrees = radiansToDegrees(PI);  // create a floating point variable 'degrees' 
                                       // and set it equal to the amount of degrees in PI (180)


rand

word rand()
(word) Returns a pseudo-random integral number in the range 0 to at least 32,767 (depending on platform).

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 ( value % 100 + 1 ) is in the range 1 to 100 ( value % 30 + 1985 ) is in the range 1985 to 2014

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.

task main()
{
  int min = -100;   // create int variable 'min' and set it to -100
  int max = 100;    // create int variable 'max' and set it to 100
 
  srand(nSysTime);  // generate seed for rand() from current system time
 
  while(true)       // infinite loop:
  {
    motor[rightMotor] = (rand() % (max-min)) + min; // set 'rightMotor' to a random number in the range: [min, max]
    motor[leftMotor]  = (rand() % (max-min)) + min; // set 'leftMotor' to a random number in the range: [min, max]
    wait1Msec(500); // wait 500 milliseconds
  }
}


randLong

long randLong()
(long) Returns a pseudo-random integral number in the range 0 to at least 2,147,483,647 (depending on platform).

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 ( value % 100 + 1 ) is in the range 1 to 100 ( value % 30 + 1985 ) is in the range 1985 to 2014

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.

task main()
{
  long min = -100;   // create long variable 'min' and set it to -100
  long max = 100;    // create long variable 'max' and set it to 100
 
  srand(nSysTime);  // generate seed for rand() from current system time
 
  while(true)       // infinite loop:
  {
    motor[rightMotor] = (randLong() % (max-min)) + min; // set 'rightMotor' to a random number in the range: [min, max]
    motor[leftMotor]  = (randLong() % (max-min)) + min; // set 'leftMotor' to a random number in the range: [min, max]
    wait1Msec(500); // wait 500 milliseconds
  }
}


sgn

short sgn(const float input)
(short) Returns a value less than 0 if input is negative, and a value greater than 0 if input is positive.
Parameter Explanation Data Type
input The number to test the sign of float
int res1 = sgn(-9.81);  // returns -1 to 'res1'
int res2 = sgn(3.14);   // returns 1 to 'res2'
int res3 = sgn(0);      // returns 0 to 'res3'


sin

float sin(const float fRadians)
(float) Returns the sine of a number of radians.
Parameter Explanation Data Type
fRadians The number to take the sine of (in radians). float
float result = sin(PI);  // create a floating point variable 'result' and
                         // set it equal to the cosine of PI (0)


sinDegrees

float sinDegrees(const float fDegrees)
(float) Returns the sine of a number of degrees.
Parameter Explanation Data Type
fDegrees The number to take the sine of (in degrees). float
float result = sinDegrees(180);  // create a floating point variable 'result' and 
                                 // set it equal to the sine of 180 degrees (0)


srand

void srand(const long nSeedValue)
(void) The pseudo-random number generator is initialized using the argument passed as nSeedValue.

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. Two different initializations with the same seed, instructs the pseudo-random generator to generate the same succession of results for the subsequent calls to rand in both cases.

Parameter Explanation Data Type
nSeedValue The seed for the pseudo-random number generator, rand() long
task main()
{
  int min = -100;   // create int variable 'min' and set it to -100
  int max = 100;    // create int variable 'max' and set it to 100
 
  srand(nSysTime);  // generate seed for rand() from current system time
 
  while(true)       // infinite loop:
  {
    motor[rightMotor] = (rand() % (max-min)) + min; // set 'rightMotor' to a random number in the range: [min, max]
    motor[leftMotor]  = (rand() % (max-min)) + min; // set 'leftMotor' to a random number in the range: [min, max]
    wait1Msec(500); // wait 500 milliseconds
  }
}


sqrt

float sqrt(const float input)
(float) Returns the square-root of input.
Parameter Explanation Data Type
input The number to take the square-root of. float
float result = sqrt(1764);  // create a floating point variable 'result' and 
                            // set it equal to the square-root of 1764 (42)