Skip to content

Commit 5e3df08

Browse files
committed
Add tests for sqrt, fmod (#612) and floating point printf/scanf (#1179)
1 parent b91e929 commit 5e3df08

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <BSTest.h>
2+
BS_ENV_DECLARE();
3+
4+
5+
void setup()
6+
{
7+
Serial.begin(115200);
8+
BS_RUN(Serial);
9+
}
10+
11+
TEST_CASE("Floating point formatting works", "[newlib]")
12+
{
13+
char buf[16];
14+
const float val = 0.02300;
15+
snprintf(buf, sizeof(buf), "%.05f", val);
16+
CHECK(String(buf) == "0.02300");
17+
float res;
18+
sscanf(buf, "%f", &res);
19+
CHECK(res == val);
20+
}
21+
22+
TEST_CASE("#612 fmod and sqrt work", "[newlib]")
23+
{
24+
CHECK(fabs(fmod(2.0, 1.5) - 0.5) < 1e-6);
25+
CHECK(fabs(fmod(-10, -3) - (-1.0)) < 1e-5);
26+
}
27+
28+
void loop()
29+
{
30+
}

0 commit comments

Comments
 (0)