Description
Calculates the square of a number: the number multiplied by itself.
Syntax
sq(x)
Parameters
x
: the number, any data type
Returns
The square of the number. (double)
Calculates the square of a number: the number multiplied by itself.
sq(x)
x
: the number, any data type
The square of the number. (double)
Because of the way the sq()
function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results.
This code will yield incorrect results:
int inputSquared = sq(Serial.parseInt()); // avoid this
Use this instead:
int input = Serial.parseInt(); // keep other operations outside the sq function
int inputSquared = sq(input);