Skip to content

Add warnings about doing operations inside macro parameters #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Language/Functions/Math/constrain.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ The code limits the sensor values to between 10 to 150.
sensVal = constrain(sensVal, 10, 150); // limits range of sensor values to between 10 and 150
----

[float]
=== Notes and Warnings
Because of the way the `constrain()` function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results.

This code will yield incorrect results:
[source,arduino]
----
int constrainedInput = constrain(Serial.parseInt(), minimumValue, maximumValue); // avoid this
----

Use this instead:
[source,arduino]
----
int input = Serial.parseInt(); // keep other operations outside the constrain function
int constrainedInput = constrain(input, minimumValue, maximumValue);
----
[%hardbreaks]

--
// HOW TO USE SECTION ENDS

Expand Down
26 changes: 26 additions & 0 deletions Language/Functions/Math/sq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ The square of the number. (double)
// OVERVIEW SECTION ENDS


// HOW TO USE SECTION STARTS
[#howtouse]
--

[float]
=== 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:
[source,arduino]
----
int inputSquared = sq(Serial.parseInt()); // avoid this
----

Use this instead:
[source,arduino]
----
int input = Serial.parseInt(); // keep other operations outside the sq function
int inputSquared = sq(input);
----
[%hardbreaks]

--
// HOW TO USE SECTION ENDS


// SEE ALSO SECTION
[#see_also]
--
Expand Down