Operadores#

Introduction#

The Operators blocks in VEXcode IQ (1st gen) handle mathematical calculations. These blocks allow for performing arithmetic and evaluating conditions. Below is a list of available blocks:

Math – Perform calculations and evaluate numerical conditions.

  • math operator – Performs addition, subtraction, multiplication, or division.

  • comparison operator – Compares two values using greater than, less than, or equal operators.

  • logical operator – Evaluates multiple conditions using and or or.

  • not operator – Inverts a Boolean value.

  • range operator – Checks if a number falls within a range.

  • pick random – Generates a random number within a specified range.

  • round number – Rounds a number to the nearest whole number.

  • math functions – Applies operations such as square root, trigonometry, logarithms, and exponentiation.

  • atan2 – Computes the inverse tangent of y/x.

  • remainder – Returns the remainder of a division operation.

Math#

math operator#

The math operator block performs basic arithmetic on the values placed on either side. It returns a result based on the project’s print precision, which defaults to 0 decimal places but can be adjusted using the set print precision block.

The Math operator reporter block.#
([0] [math_plus v] [0])

Parameters

Description

value 1

The first number used in the operation.

operator

The mathematical operator to use:

  • + - Addition
  • - - Subtraction
  • * - Multiplication
  • / - Division

value 2

The second number used in the operation.

Example

cuando empezó :: hat events
[Perform basic addition and show two decimal places.]
Establezca la precisión de impresión en [0.01 v] en la pantalla
imprimir ([10] [math_plus v] [10.5]) en la pantalla ▶

comparison operator#

The comparison operator block returns a Boolean indicating whether the comparison between two values is true or false.

  • True – The comparison is correct (e.g., 5 > 3 returns True).

  • False – The comparison is incorrect (e.g., 2 ≥ 5 returns False).

The Comparison operator Boolean block.#
<[0] [math_equal v] [0]>

Parameter

Description

value 1

The first value to compare.

operator

The comparison to use:

  • = - Equal to
  • < - Less than
  • - Less than or equal to
  • > - Greater than
  • - Greater than or equal to

value 2

The second value to compare.

Example

cuando empezó :: hat events
[Turn right until the heading reaches 90 degrees.]
turno [derecha v]
esperar [0.5] segundos
esperar hasta <(rumbo de la unidad en grados) [math_greater_than v] [90]>
deja de conducir

logical operator#

The logical operator block returns a Boolean indicating whether the logical condition between multiple values is true or false.

  • True – The logic condition is met.

  • False – The logic condition is not met.

The Logical Operator Boolean block.#
<<> [and v] <>>

Parameter

Description

condition 1

The first Boolean condition to evaluate.

operator

The logical operator to use:

  • and - Returns True if both conditions are True.
  • or - Returns True if at least one condition is True.

condition 2

The second Boolean condition to evaluate.

Example

cuando empezó :: hat events
[Display if the up and down buttons are pressed.]
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <<¿Botón del cerebro [arriba v] presionado?> [and v] <¿Botón del cerebro [abajo v] presionado?>> entonces
imprimir [Buttons pressed!] en la pantalla ▶
fin
fin

not operator#

The not operator block inverts the result of a Boolean block. If the input is True, it returns False, and if the input is False, it returns True.

  • True – The input condition would normally return False.

  • False – The input condition would normally return True.

The Not Operator Boolean block.#
<no <>>

Parameter

Description

condition

The Boolean condition to be inverted.

Example

cuando empezó :: hat events
[Turn until the robot is facing left. ]
para siempre
si <no <(rumbo de la unidad en grados) [math_greater_than v] [270]>> entonces
turno [derecha v]
demás
deja de conducir

range operator#

The range operator block returns a Boolean indicating whether a value falls within a specified range.

  • True – If the value is within the range.

  • False – If the value is outside the range.

The Range Operator Boolean block.#
<[0] [math_less_than v] [0] [math_less_than v] [0]>

Parameter

Description

first operator

The comparison operator to use:

  • < - Less than
  • ≤ - Less than or equal to
  • > - Greater than
  • ≥ - Greater than or equal to

value

The value to check.

second operator

The comparison operator to use:

  • < - Less than
  • ≤ - Less than or equal to
  • > - Greater than
  • ≥ - Greater than or equal to

Example

cuando empezó :: hat events
[Turn and display when facing forward or back. ]
girar [derecha v] por [360] grado ◀ y no esperes
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <[270] [math_greater_than v] (rumbo de la unidad en grados) [math_greater_than v] [90]> entonces
imprimir [Facing backward!] en la pantalla ▶
demás
imprimir [Facing forward!] en la pantalla ▶

pick random#

The pick random block returns a random integer within the specified range.

The Pick Random reporter block.#
elige al azar de [1] a [10]

Parameters

Description

min

The lowest possible number that can be picked.

max

The highest possible number that can be picked.

Examples

cuando empezó :: hat events
[Display a number between 1 and 10.]
imprimir (elige al azar de [1] a [10]) ▶

round number#

The round number block returns the given number rounded to the nearest whole number, following standard rounding rules:

  • If the decimal is 0.5 or greater, the number rounds up.

  • If the decimal is less than 0.5, the number rounds down.

The Round Number reporter block.#
(redondear de [0] a [0] decimal)

Parameter

Description

number

The number to round.

decimal places

The amount of decimals places to round to.

Example

cuando empezó :: hat events
[Display the rounded result of 10 / 3.]
Establezca la precisión de impresión en [0.01 v] en la pantalla
imprimir (redondear de ([10] [math_division v] [3]) a [1] decimal) en la pantalla ▶

math functions#

The math functions block applies a selected mathematical function to a given number and returns the result. It supports operations such as absolute value, rounding, square roots, trigonometric functions, logarithms, and exponentiation.

The Math Functions reporter block.#
[abdominales v] de [0]

Parameter

Description

function

The mathematical operation to apply to the input value:

  • abs - Absolute value
  • floor - Rounds down
  • ceiling - Rounds up
  • sqrt - Square root
  • sin - Sine
  • cos - Cosine
  • tan - Tangent
  • asin - Inverse sine
  • acos - Inverse cosine
  • atan - Inverse tangent
  • ln - Natural logarithm
  • log - Base 10 logarithm
  • e^ - Euler’s number raised to a power
  • 10^ - 10 raised to a power
  • negative - Returns the negative of the number

number

The number to apply the function to.

Example

cuando empezó :: hat events
[Display the square root of 16.]
imprimir ([raíz cuadrada v] de [16]) en la pantalla ▶

atan2#

The atan2 block returns the inverse tangent of Y/X as an angle in degrees, representing the angle between the positive X-axis and the point (X, Y).

(atan2 of x:[4] y:[3])

Parameter

Description

x

The horizontal position of the point, measured from the origin (0,0).

y

The vertical position of the point, measured from the origin (0,0).

Example

cuando empezó :: hat events
[Calculate the angle from current position (4, 3).]
imprimir (atan2 of x:[4] y:[3]) en la pantalla ▶

remainder#

The remainder block returns the remainder of the division operation between two values.

The Remainder reporter block.#
(remainder of [0] / [0])

Parameter

Description

dividend

The number to be divided.

divisor

The number to divide by.

Example

cuando empezó :: hat events
[Display the remainder of 10 / 3.]
imprimir (remainder of [10] / [3]) en la pantalla ▶