void Helper_test::testAbsolute() { const double pos = 1; const double neg = -1; const double expected = 1; const double resultAbsOnPos = absolut(pos); CPPUNIT_ASSERT_EQUAL(expected, resultAbsOnPos); const double resultAbsOnNeg = absolut(neg); CPPUNIT_ASSERT_EQUAL(expected, resultAbsOnNeg); }
double euler(double e){ double newpotenz = potenz(1+(1/n),n); a_neu = (a_alt + newpotenz)/2; if ((absolut(a_alt - a_neu)) < e){ return a_neu; } else{ a_alt = a_neu; n += 1; euler (e); } return a_neu; }
void process_output(char *msg_buf, float phi, float xleft, float xright) { int backward, forward; float center; float xc, theta; backward = (xleft <= -0.95 || xright >= 0.95); forward = (xleft >= -0.1 && xright <= 0.1); center = (xleft + xright) / 2; printf("xleft %.4f, xright %.4f, center %.4f\n", xleft, xright, center); if (absolut(center) <= 0.2) { printf("center\n"); xc = 100; if (forward) { theta = 0.00025; } else if (backward) { theta = -0.00025; } else { theta = 0.0001; } } else if (center > 0.6 && center < 0.8) { printf("right\n"); xc = 10 * D; if (forward) { theta = 0.01; } else if (backward) { theta = -0.01; } else { theta = 0.005; } } else if (center >= 0.8) { printf("extreme right\n"); xc = D; if (forward) { theta = 0.05; } else if (backward) { theta = -0.05; } else { theta = 0.025; } } else if (center < -0.6 && center > -0.8) { printf("left\n"); xc = -10 * D; if (forward) { theta = 0.01; } else if (backward) { theta = -0.01; } else { theta = 0.005; } } else if (center <= -0.8) { printf("extreme left\n"); xc = -D; if (forward) { theta = 0.05; } else if (backward) { theta = -0.05; } else { theta = 0.025; } } memset(msg_buf, 0, BUFSIZ); sprintf(msg_buf, "xc %f theta %f\n", xc, theta); }