Skip to content

Commit 644052e

Browse files
Get rid of carriage returns in some of the tests.
1 parent 2991c7e commit 644052e

File tree

2 files changed

+174
-174
lines changed

2 files changed

+174
-174
lines changed

test/basics/qthread_fp.c

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
#ifdef HAVE_CONFIG_H
2-
#include <config.h>
3-
#endif
4-
5-
#include <math.h>
6-
#include <qthread/qthread.h>
7-
#include <stdio.h>
8-
#include <stdlib.h>
9-
10-
#include "argparsing.h"
11-
12-
// https://www.geeksforgeeks.org/comparison-float-value-c/
13-
// https://dotnettutorials.net/lesson/taylor-series-using-recursion-in-c/
14-
// https://www.studytonight.com/c/programs/important-concepts/sum-of-taylor-series
15-
16-
struct parts {
17-
int length;
18-
float exp;
19-
float ans;
20-
aligned_t cond;
21-
};
22-
23-
// https://www.w3resource.com/c-programming-exercises/math/c-math-exercise-24.php
24-
static float taylor_exponential_core(int n, float x) {
25-
float exp_sum = 1;
26-
for (int i = n - 1; i > 0; --i) { exp_sum = 1 + x * exp_sum / i; }
27-
return exp_sum;
28-
}
29-
30-
static aligned_t taylor_exponential(void *arg) {
31-
struct parts *te = (struct parts *)arg;
32-
te->ans = taylor_exponential_core(te->length, te->exp);
33-
return 0;
34-
}
35-
36-
static void checkFloat(void) {
37-
struct parts teParts = {250, 9.0f, 0.0f};
38-
int ret = -1;
39-
qthread_empty(&teParts.cond);
40-
41-
ret = qthread_fork(taylor_exponential, &teParts, &teParts.cond);
42-
test_check(ret == QTHREAD_SUCCESS);
43-
44-
ret = qthread_readFF(NULL, &teParts.cond);
45-
test_check(ret == QTHREAD_SUCCESS);
46-
}
47-
48-
int main(void) {
49-
float ans = taylor_exponential_core(250, 9.0);
50-
float expected = 8103.083984f;
51-
float rel_error = fabsf(ans - expected) / fabsf(expected);
52-
float threshold = 1E-7f;
53-
test_check(rel_error < threshold);
54-
55-
int status = qthread_initialize();
56-
test_check(status == QTHREAD_SUCCESS);
57-
58-
checkFloat();
59-
return EXIT_SUCCESS;
60-
}
1+
#ifdef HAVE_CONFIG_H
2+
#include <config.h>
3+
#endif
4+
5+
#include <math.h>
6+
#include <qthread/qthread.h>
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
10+
#include "argparsing.h"
11+
12+
// https://www.geeksforgeeks.org/comparison-float-value-c/
13+
// https://dotnettutorials.net/lesson/taylor-series-using-recursion-in-c/
14+
// https://www.studytonight.com/c/programs/important-concepts/sum-of-taylor-series
15+
16+
struct parts {
17+
int length;
18+
float exp;
19+
float ans;
20+
aligned_t cond;
21+
};
22+
23+
// https://www.w3resource.com/c-programming-exercises/math/c-math-exercise-24.php
24+
static float taylor_exponential_core(int n, float x) {
25+
float exp_sum = 1;
26+
for (int i = n - 1; i > 0; --i) { exp_sum = 1 + x * exp_sum / i; }
27+
return exp_sum;
28+
}
29+
30+
static aligned_t taylor_exponential(void *arg) {
31+
struct parts *te = (struct parts *)arg;
32+
te->ans = taylor_exponential_core(te->length, te->exp);
33+
return 0;
34+
}
35+
36+
static void checkFloat(void) {
37+
struct parts teParts = {250, 9.0f, 0.0f};
38+
int ret = -1;
39+
qthread_empty(&teParts.cond);
40+
41+
ret = qthread_fork(taylor_exponential, &teParts, &teParts.cond);
42+
test_check(ret == QTHREAD_SUCCESS);
43+
44+
ret = qthread_readFF(NULL, &teParts.cond);
45+
test_check(ret == QTHREAD_SUCCESS);
46+
}
47+
48+
int main(void) {
49+
float ans = taylor_exponential_core(250, 9.0);
50+
float expected = 8103.083984f;
51+
float rel_error = fabsf(ans - expected) / fabsf(expected);
52+
float threshold = 1E-7f;
53+
test_check(rel_error < threshold);
54+
55+
int status = qthread_initialize();
56+
test_check(status == QTHREAD_SUCCESS);
57+
58+
checkFloat();
59+
return EXIT_SUCCESS;
60+
}

test/basics/qthread_fp_double.c

Lines changed: 114 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,114 @@
1-
#ifdef HAVE_CONFIG_H
2-
#include <config.h>
3-
#endif
4-
5-
#include <assert.h>
6-
#include <math.h>
7-
#include <qthread/qthread.h>
8-
#include <stdio.h>
9-
#include <stdlib.h>
10-
11-
#include "argparsing.h"
12-
13-
// https://www.geeksforgeeks.org/comparison-float-value-c/
14-
// https://dotnettutorials.net/lesson/taylor-series-using-recursion-in-c/
15-
// https://www.studytonight.com/c/programs/important-concepts/sum-of-taylor-series
16-
17-
struct parts {
18-
int length;
19-
double exp;
20-
double ans;
21-
aligned_t cond;
22-
};
23-
24-
// https://www.w3resource.com/c-programming-exercises/math/c-math-exercise-24.php
25-
static double taylor_exponential_core(int n, double x, int yield) {
26-
double exp_sum = 1;
27-
for (int i = n - 1; i > 0; --i) {
28-
exp_sum = 1 + x * exp_sum / i;
29-
if (yield) qthread_yield();
30-
}
31-
return exp_sum;
32-
}
33-
34-
static aligned_t taylor_exponential(void *arg) {
35-
struct parts *te = (struct parts *)arg;
36-
te->ans = taylor_exponential_core(te->length, te->exp, 1);
37-
return 0;
38-
}
39-
40-
static void startQthread(struct parts *teParts) {
41-
qthread_empty(&teParts->cond);
42-
43-
int ret = qthread_fork(taylor_exponential, teParts, &teParts->cond);
44-
test_check(ret == QTHREAD_SUCCESS);
45-
}
46-
47-
static aligned_t checkDoubleAsQthreads(void) {
48-
struct parts teParts1 = {250, 9.0, 0.0};
49-
struct parts teParts2 = {50, 3.0, 0.0};
50-
struct parts teParts3 = {150, 11.0, 0.0};
51-
52-
startQthread(&teParts1);
53-
startQthread(&teParts2);
54-
startQthread(&teParts3);
55-
56-
int ret = qthread_readFF(NULL, &teParts1.cond);
57-
test_check(ret == QTHREAD_SUCCESS);
58-
59-
ret = qthread_readFF(NULL, &teParts2.cond);
60-
test_check(ret == QTHREAD_SUCCESS);
61-
62-
ret = qthread_readFF(NULL, &teParts3.cond);
63-
test_check(ret == QTHREAD_SUCCESS);
64-
65-
double threshold = 1E-15;
66-
67-
double expected_1 = 8103.0839275753824;
68-
double rel_error_1 = fabs(expected_1 - teParts1.ans) / fabs(expected_1);
69-
test_check(rel_error_1 < threshold);
70-
71-
double expected_2 = 20.085536923187668;
72-
double rel_error_2 = fabs(expected_2 - teParts2.ans) / fabs(expected_2);
73-
test_check(rel_error_2 < threshold);
74-
75-
double expected_3 = 59874.141715197809;
76-
double rel_error_3 = fabs(expected_3 - teParts3.ans) / fabs(expected_3);
77-
test_check(rel_error_3 < threshold);
78-
79-
return 0;
80-
}
81-
82-
static void checkDoubleAsQthread(void) {
83-
int ret = -1;
84-
struct parts teParts = {250, 9.0, 0.0};
85-
qthread_empty(&teParts.cond);
86-
87-
ret = qthread_fork(taylor_exponential, &teParts, &teParts.cond);
88-
test_check(ret == QTHREAD_SUCCESS);
89-
90-
ret = qthread_readFF(NULL, &teParts.cond);
91-
test_check(ret == QTHREAD_SUCCESS);
92-
93-
double expected = 8103.0839275753824;
94-
double rel_error = fabs(expected - teParts.ans) / fabs(expected);
95-
test_check(rel_error < 1E-15);
96-
}
97-
98-
static void checkDouble(void) {
99-
double ans = taylor_exponential_core(250, 9.0, 0);
100-
double expected = 8103.0839275753824;
101-
double rel_error = fabs(expected - ans) / fabs(expected);
102-
test_check(rel_error < 1E-15);
103-
}
104-
105-
int main(void) {
106-
checkDouble();
107-
108-
int status = qthread_initialize();
109-
test_check(status == QTHREAD_SUCCESS);
110-
111-
checkDoubleAsQthread();
112-
checkDoubleAsQthreads();
113-
return EXIT_SUCCESS;
114-
}
1+
#ifdef HAVE_CONFIG_H
2+
#include <config.h>
3+
#endif
4+
5+
#include <assert.h>
6+
#include <math.h>
7+
#include <qthread/qthread.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
11+
#include "argparsing.h"
12+
13+
// https://www.geeksforgeeks.org/comparison-float-value-c/
14+
// https://dotnettutorials.net/lesson/taylor-series-using-recursion-in-c/
15+
// https://www.studytonight.com/c/programs/important-concepts/sum-of-taylor-series
16+
17+
struct parts {
18+
int length;
19+
double exp;
20+
double ans;
21+
aligned_t cond;
22+
};
23+
24+
// https://www.w3resource.com/c-programming-exercises/math/c-math-exercise-24.php
25+
static double taylor_exponential_core(int n, double x, int yield) {
26+
double exp_sum = 1;
27+
for (int i = n - 1; i > 0; --i) {
28+
exp_sum = 1 + x * exp_sum / i;
29+
if (yield) qthread_yield();
30+
}
31+
return exp_sum;
32+
}
33+
34+
static aligned_t taylor_exponential(void *arg) {
35+
struct parts *te = (struct parts *)arg;
36+
te->ans = taylor_exponential_core(te->length, te->exp, 1);
37+
return 0;
38+
}
39+
40+
static void startQthread(struct parts *teParts) {
41+
qthread_empty(&teParts->cond);
42+
43+
int ret = qthread_fork(taylor_exponential, teParts, &teParts->cond);
44+
test_check(ret == QTHREAD_SUCCESS);
45+
}
46+
47+
static aligned_t checkDoubleAsQthreads(void) {
48+
struct parts teParts1 = {250, 9.0, 0.0};
49+
struct parts teParts2 = {50, 3.0, 0.0};
50+
struct parts teParts3 = {150, 11.0, 0.0};
51+
52+
startQthread(&teParts1);
53+
startQthread(&teParts2);
54+
startQthread(&teParts3);
55+
56+
int ret = qthread_readFF(NULL, &teParts1.cond);
57+
test_check(ret == QTHREAD_SUCCESS);
58+
59+
ret = qthread_readFF(NULL, &teParts2.cond);
60+
test_check(ret == QTHREAD_SUCCESS);
61+
62+
ret = qthread_readFF(NULL, &teParts3.cond);
63+
test_check(ret == QTHREAD_SUCCESS);
64+
65+
double threshold = 1E-15;
66+
67+
double expected_1 = 8103.0839275753824;
68+
double rel_error_1 = fabs(expected_1 - teParts1.ans) / fabs(expected_1);
69+
test_check(rel_error_1 < threshold);
70+
71+
double expected_2 = 20.085536923187668;
72+
double rel_error_2 = fabs(expected_2 - teParts2.ans) / fabs(expected_2);
73+
test_check(rel_error_2 < threshold);
74+
75+
double expected_3 = 59874.141715197809;
76+
double rel_error_3 = fabs(expected_3 - teParts3.ans) / fabs(expected_3);
77+
test_check(rel_error_3 < threshold);
78+
79+
return 0;
80+
}
81+
82+
static void checkDoubleAsQthread(void) {
83+
int ret = -1;
84+
struct parts teParts = {250, 9.0, 0.0};
85+
qthread_empty(&teParts.cond);
86+
87+
ret = qthread_fork(taylor_exponential, &teParts, &teParts.cond);
88+
test_check(ret == QTHREAD_SUCCESS);
89+
90+
ret = qthread_readFF(NULL, &teParts.cond);
91+
test_check(ret == QTHREAD_SUCCESS);
92+
93+
double expected = 8103.0839275753824;
94+
double rel_error = fabs(expected - teParts.ans) / fabs(expected);
95+
test_check(rel_error < 1E-15);
96+
}
97+
98+
static void checkDouble(void) {
99+
double ans = taylor_exponential_core(250, 9.0, 0);
100+
double expected = 8103.0839275753824;
101+
double rel_error = fabs(expected - ans) / fabs(expected);
102+
test_check(rel_error < 1E-15);
103+
}
104+
105+
int main(void) {
106+
checkDouble();
107+
108+
int status = qthread_initialize();
109+
test_check(status == QTHREAD_SUCCESS);
110+
111+
checkDoubleAsQthread();
112+
checkDoubleAsQthreads();
113+
return EXIT_SUCCESS;
114+
}

0 commit comments

Comments
 (0)