Math
The Math section in your block programming environment equips you with a versatile toolkit for performing various mathematical operations. These blocks enable your robot to make precise calculations, process sensor data, and execute complex maneuvers with greater accuracy.
number
A fixed numerical value that can be used in calculations, comparisons, or as input to other blocks.
Key points:
Fixed value: The number cannot be changed during program execution.
Data type: Can represent integers, decimals, or other numeric formats as needed.
Usage: Used in various calculations, comparisons, and as input to other blocks.
+
Returns the sum of two numbers.
Key points:
The order of operands is not important.
Can be used with both integers and floating-point numbers.
Often combined with other arithmetic operations to form more complex expressions.
-
Returns the difference between two numbers.
Key points:
The order of operands is important. Subtracts the second number from the first number.
Can be used with both integers and floating-point numbers.
Often combined with other arithmetic operations to form more complex expressions.
*
Returns the product of two numbers.
Key points:
The order of operands is not important.
Can be used with both integers and floating-point numbers.
Often combined with other arithmetic operations to form more complex expressions.
/
Returns the quotient of the first number (dividend) divided by the second number (divisor).
Key points:
Division by zero: Attempting to divide a number by zero results in infinity or negative infinity.
Integer division: Dividing two integers results in an integer quotient if dividend is divisible by the divisor. If not divisible, return a float number.
Floating-point division: Dividing floating-point numbers produces a floating-point result.
^
Returns the first number raised to the power of the second number.
Key points:
The first number is the base, and the second number is the exponent.
Exponentiation can be used for various calculations, including growth models, scientific formulas, and financial calculations.
negative
Used as a unary operator to negate a numerical value.
Key points:
Can be applied to both integers and floating-point numbers.
Often used in mathematical calculations and expressions.
square root
Calculates the square root of a non-negative number.
Key points:
Returns the value that, when multiplied by itself, equals the input number.
The square root of an integer may be a float number.
If a negative number is provided, the result becomes NaN.
absolute
Calculates the absolute value of a number.
Function:
Takes a real number (positive, negative, or zero) as input. Returns the distance of the number from zero, which is always a non-negative value.
Key points:
The absolute value of a positive number is the number itself.
The absolute value of a negative number is its positive counterpart.
The absolute value of zero is zero.
You can choose the other operations from the drop list of absolute blocks:
ln. Calculates the natural logarithm of a positive number.
log10: Calculates the logarithm base 10 of a positive number.
e^: Calculates the exponential of a number, where the base is the mathematical constant 'e' (approximately 2.71828).
10^: Calculates the exponential of a number, where the base is 10.
sin
Calculates the sine of an angle in degree (not radian).
Key points:
Returns a value between -1 and 1, representing the sine of the angle.
The sine function is periodic with a period of 2π radians (or 360 degrees).
The sine of 0 is 0 (sin(0) = 0).
The sine of π/2 radians (or 90 degrees) is 1 (sin(π/2) = 1).
The sine of π radians (or 180 degrees) is 0 (sin(π) = 0).
The sine of 3π/2 radians (or 270 degrees) is -1 (sin(3π/2) = -1).
You can choose the other operations from the drop list of sin blocks:
cos: Calculates the cosine of an angle in degree (not radian).
tan: Calculates the tangent of an angle in degree (not radian). Returns a value, which can be any real number, representing the tangent of the angle. The tangent function is undefined for angles that are odd multiples of π/2 radians (or 90 degrees).
asin: Calculates the arcsine (or inverse sine) of a number, which is the angle whose sine is the input number. Takes a number between -1 and 1 as input and returns an angle in degree. The arccosine of a number outside the range of -1 to 1 is NaN.
acos: Calculates the arccosine (or inverse cosine) of a number, which is the angle whose cosine is the input number. Takes a number between -1 and 1 as input and returns an angle in degree. The arccosine of a number outside the range of -1 to 1 is NaN.
atan: Calculates the arctangent (or inverse tangent) of a number, which is the angle whose tangent is the input number. It takes a real number (positive, negative, or zero) as input.
atan2
Returns a numerical value between -180 and +180 degrees, representing the counterclockwise angle between the positive X axis, and the point (x, y).
π
A mathematical constant representing the ratio of the circumference of a circle to its diameter, which is approximately 3.14159.
You can choose the other constants from the dropdown list:
e: A mathematical constant that is the base of the natural logarithm. The number is approximately 2.71828.
φ: Golden Ratio or Phi. The value is approximately 1.61803.
sqrt(2): square root of 2. Roughly 1.4142.
sqrt(1/2): square root of 1/2. Roughly 0.7071.
∞: A concept representing a value that is greater than any finite number. There are two types of infinity: positive infinity (+∞) and negative infinity (-∞). Positive infinity represents a value greater than any positive number, while negative infinity represents a value smaller than any negative number.
is even
Determines whether an integer is even or not.
Key points:
Returns True if the integer is even, False if the integer is odd.
An even integer is any integer that is exactly divisible by 2 (i.e., leaves no remainder when divided by 2).
An odd integer is any integer that is not exactly divisible by 2.
You can choose the tests of numbers from the dropdown list:
odd: Determines whether an integer is odd or not.
prime: Determines whether an integer is a prime number or not. A prime number is divisible only by 1 and itself.
whole: Returns true if the number is an integer (whole number), false if it's a fraction or decimal.
positive: Returns true if the number is greater than zero. Returns false otherwise.
negative: Returns true if the number is less than zero, false otherwise.
divisible by: Returns true if the number is divisible by another given number.
round
Rounds a floating-point number to the nearest integer or to a specified number of decimal places.
Key points:
If the fractional part is 0.5 or greater, the number is rounded up. If the fractional part is less than 0.5, the number is rounded down.
Rounding helps to simplify calculations and make numbers easier to work with.
Rounding can introduce errors, so it is important to be mindful of the context in which it is used.
From the drop list, you can choose “round up”, or “round down”.
round up: Rounds a floating-point number up to the nearest integer or to a specified number of decimal places.
round down: Rounds a floating-point number down to the nearest integer or to a specified number of decimal places.
sum of list
Returns the sum of all numbers in a list.
Key points:
Return a single float number.
The list can be of any length.
From the drop down list, you can find the other operations against a list:
min of list: Finds the minimum (smallest) value in a list of numbers.
max of list: Finds the maximum (largest) value in a list of numbers.
average of list: Calculates the average (mean) of all elements in a list of numbers.
median of list: Calculates the median value of a list of numbers.
modes of list: Calculates the modes (most frequent items) of a list of numbers.
standard deviation of list: Calculates the standard deviation of a list of numbers.
random item of list: Selects a random item from a list of numbers.
remainder of
Calculates the remainder when one integer is divided by another.
Key points:
Both inputs must be integers.
Returns an integer representing the remainder of the division.
constrain low high
Limits a given value to a specified range defined by a lower bound (low) and an upper bound (high). The limits are inclusive.
Key points:
If the given value is within the range [low, high], returns value.
If the given value is less than low, returns low.
If the given value is greater than high, returns high.
random integer from to
Generates a random integer within a specified range, inclusive of both the lower and upper bounds.
Key points:
Uses a random number generator to produce a value within the range.
Ensures that the lower bound is less than or equal to the upper bound.
The generated integer has a uniform distribution, meaning each value in the range has an equal probability of being chosen.
random fraction
Generates a random fraction between 0 and 1.
Function:
Takes no input.
Returns a floating-point number between 0 (inclusive) and 1 (exclusive).
Key points:
Uses a random number generator to produce a value within the range [0, 1).
The generated fraction has a uniform distribution, meaning each value in the range has an equal probability of being chosen.