Skip to content

Math

Use the Math blocks to include numbers in code and perform mathematical operations.

Basic math

  • Basic Operators

    Use this block to perform basic mathematical operations on two numbers and return the result. Available operations include addition, subtraction, multiplication, division, and exponents.

  • Remainder

    This block returns the remainder from dividing two numbers. For example, the block shown above returns a value of 4.

  • Common Constants

    Use this block to return the value of a common constant, including pi, the exponential constant, the golden ratio, the square root of 2, the square root of ½, and infinity.

Functions

  • Scientific Functions

    Use this block to perform a function on a single number and return the result. Available functions include square root, absolute value, inverse, natural logarithm, base 10 logarithm, exponential, and power of 10.

  • Trigonometric Functions

    Use this block to perform a trigonometric function on a single number in degrees and return the result. Available functions include sine, cosine, tangent, arcsine, arccosine, and arctangent.

  • Rounding Functions

    Use this block to round numbers to the nearest integer and return the result. Available options include:

    • round: Round down for decimals less than 0.5, round up for decimals greater than or equal to 0.5.
    • round up: Always round up the number, regardless of the decimal value.
    • round down: Always round down the number, regardless of the decimal value.
  • Statistical Functions

    Use this block to calculate statistics on two or more numbers and return the result. Unlike the other blocks in the Math group, this block requires a list of numbers instead of a single number. Available options include:

    • sum: Add together all numbers in the list.
    • min: Return the smallest number in the list.
    • max: Return the largest number in the list.
    • average: Return the mean of the numbers in the list.
    • median: Return the "middle" value in the list.
    • mode: Return the value that appears most often in the list.
    • standard deviation: Return the standard deviation of the numbers in the list.
    • random item: Return a random number in the list.

Random numbers

  • Random Integer

    This block returns an random integer between the two specified numbers.

  • Random Fraction

    This block returns a random decimal between 0 and 1.0.

Check a number

Use this block to check the type of number and return a value of true or false. The block can check if a number is even, odd, prime, whole, positive, negative, or divisible by a given number.

Constrain a number

This block returns a number that is constrained between two specified values. If the number is higher than the specified high number, the block returns the high number. If the number is lower than the specified low number, the block returns the low number.