Subscribed unsubscribe Subscribe Subscribe

sq() / sprt() / pow()

sq()
sq() \ Language (API) \ Processing 2+

squares a number (multiplies a number by itself)
the result is always a positive number
return float

noStroke();

float a = sq(1);
float b = sq(-5);
float c = sq(9);

rect(0,25,a,10);
rect(0,45,b,10);
rect(0,65,c,10);
// rect(startX,startY,width,height)

print(a,b,c);
// console: 1.0, 25.0, 81.0

sqrt()
sqrt() \ Language (API) \ Processing 2+

calculate the square root of number
rerurn float

float a = sqrt(6561);
float b = sqrt(625);
float c = sqrt(1);

rect(0,25,a,10);
rect(0,45,b,10);
rect(0,65,c,10);
// rect(startX,startY,width,height)

print(a,b,c);
// console: 81.0 25.0 1.0


pow()
pow() \ Language (API) \ Processing 2+

function is an efficient way of multiplying numbers
return float

float a = pow(1,3);
// "a" to 1*1*1 = 1

float b = pow(3,5);
// "b" to 3*3*3*3*3 = 243

float c = pow(3,-5);
// "c" to 1 / (3*3*3*3*3) = 1/243 = 0.0041

float d = pow(-3,5);
// "d" to -3*-3*-3*-3*-3 = -243

print(a, b, c, d);
// console: 1.0 243.0 0.004115226 -243.0