sq()

Description

Calculates the square of a number: the number multiplied by itself.

Syntax

sq(x)

Parameter Values

  • x: the number. Allowed data types: any data type.

Return Values

  • The square of the number. Data type: double.

※ NOTES AND WARNINGS:

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);

See Also

Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.