Skip to content

Latest commit

 

History

History
85 lines (59 loc) · 1.42 KB

sq.adoc

File metadata and controls

85 lines (59 loc) · 1.42 KB
title categories subCategories
sq()
Functions
Math

sq(x)

Description

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

Syntax

sq(x)

Parameters

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

Returns

The square of the number. Data type: int if the argument type is smaller than an int (e.g. char), otherwise the returned value has the same type as the argument.

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