diff --git a/apps/tests.c b/apps/tests.c index 0ef511d2..e6bd093b 100644 --- a/apps/tests.c +++ b/apps/tests.c @@ -274,6 +274,31 @@ static int join_test(void* arg) return 0; } +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327950288 /* pi */ +#endif + +static int pi(void* arg) +{ + double x, sum, step; + int i, num_steps = 100000000; + + sum = 0.0; + step = 1.0 / (double)num_steps; + + for (i = 0; i < num_steps; i++) { + x = (i + 0.5) * step; + sum += 4.0 / (1.0 + x * x); + } + + x = M_PI - sum * step; + x *= 10000.0; + + kprintf("Distance to PI = %u/10000\n", (uint32_t) x); + + return 0; +} + int test_init(void) { // char* argv[] = {"/bin/mshell", NULL}; @@ -292,6 +317,7 @@ int test_init(void) //create_kernel_task(NULL, mail_ping, NULL, NORMAL_PRIO); //create_kernel_task(NULL, mail_noise, NULL, NORMAL_PRIO); //create_kernel_task(NULL, svm_test, NULL, NORMAL_PRIO); + //create_kernel_task(NULL, pi, NULL, NORMAL_PRIO); //create_user_task(NULL, "/bin/hello", argv); create_user_task(NULL, "/bin/tests", argv); //create_user_task(NULL, "/bin/jacobi", argv);