forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.ino
30 lines (24 loc) · 998 Bytes
/
math.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
Small math example, checking whether we can support various Arduino math operations.
Meant for debugging **only**
Released to public domain
*/
void setup() {
Serial.begin(115200);
// checking if we can support Arduino functions
Serial.printf("abs(-3)\n = %d", abs(-3));
Serial.printf("abs(+3)\n = %d", abs(3));
Serial.printf("abs(-3.5)\n = %f", abs(-3.5));
Serial.printf("abs(+3.5)\n = %f", abs(3.5));
Serial.printf("round(2.9)\n = %f", round(2.9));
Serial.printf("constrain(5, 1, 15) = %d\n", constrain(5, 1, 15));
Serial.printf("constrain(16, 1, 15) = %d\n", constrain(16, 1, 15));
// the same thing, but with c++ std::..., which should not cause any conflicts
Serial.printf("std::abs(-3) = %d\n", std::abs(-3));
Serial.printf("std::abs(+3) = %d\n", std::abs(3));
Serial.printf("std::abs(-3.5) = %f\n", std::abs(-3.5));
Serial.printf("std::abs(+3.5) = %f\n", std::abs(3.5));
Serial.printf("std::round(2.9) = %f\n", std::round(2.9));
}
void loop() {
}