Name

sqrt()

Description

Calculates the square root of a number. The square root of a number is always positive, even though there may be a valid negative root. The square root s of number a is such that s*s = a. It is the opposite of squaring.

Examples

  • size(400, 400);
    noStroke();
    float a = sqrt(104976);   // Sets 'a' to 324
    float b = sqrt(10000);  // Sets 'b' to 100
    float c = sqrt(256);   // Sets 'c' to 16
    rect(0, 100, a, 40);
    rect(0, 180, b, 40);
    rect(0, 260, c, 40);
    Image output for example 1

Syntax

  • sqrt(n)

Parameters

  • n(float)non-negative number

Return

  • float

Related

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.