Skip to content

Commit afdbba3

Browse files
mkaivoper1234
andauthored
Add an example code to abs() [CNT-1196] (#841)
* Add an example code to abs() CNT-1196 Hi, we got a request to add an example code of abs(). Could this work? It is a pretty straightforward function. See the Jira task here: https://arduino.atlassian.net/browse/CNT-1196 * Update abs.adoc * Update Language/Functions/Math/abs.adoc Co-authored-by: per1234 <[email protected]> Co-authored-by: per1234 <[email protected]>
1 parent 86383e1 commit afdbba3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: Language/Functions/Math/abs.adoc

+27
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,34 @@ Calculates the absolute value of a number.
4545
// HOW TO USE SECTION STARTS
4646
[#howtouse]
4747
--
48+
[float]
49+
=== Example Code
50+
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
51+
Prints the absolute value of variable `x` to the Serial Monitor.
4852

53+
[source,arduino]
54+
----
55+
void setup() {
56+
Serial.begin(9600);
57+
while (!Serial) {
58+
; // wait for serial port to connect. Needed for native USB port only
59+
}
60+
int x = 42;
61+
Serial.print("The absolute value of ");
62+
Serial.print(x);
63+
Serial.print(" is ");
64+
Serial.println(abs(x));
65+
x = -42;
66+
Serial.print("The absolute value of ");
67+
Serial.print(x);
68+
Serial.print(" is ");
69+
Serial.println(abs(x));
70+
}
71+
72+
void loop() {
73+
}
74+
----
75+
[%hardbreaks]
4976

5077
[float]
5178
=== Notes and Warnings

0 commit comments

Comments
 (0)