Name

sq()

Description

Squares a number (multiplies a number by itself). The result is always a positive number, as multiplying two negative numbers always yields a positive result. For example, -1 * -1 = 1.

Examples

  • size(400, 400);
    noStroke();
    float a = sq(4);   // Sets 'a' to 16
    float b = sq(-10);  // Sets 'b' to 100
    float c = sq(18);   // Sets 'c' to 324
    rect(0, 100, a, 40);
    rect(0, 180, b, 40);
    rect(0, 260, c, 40);
    Image output for example 1

Syntax

  • sq(n)

Parameters

  • n(float)number to square

Return

  • float

Related