Commit 14aeba10 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Fixed unsigned integer comparison problem.

parent 0c91e4d7
#include "func_ptr.h"
double bisec(func_ptr f, double left, double right, double epsilon, unsigned int *steps) {
int i;
double mid;
double bisec(func_ptr f, double left, double right,
double epsilon, unsigned int *steps) {
double mid, fmid;
for( i = 1; fabs(right - left) > 2 * epsilon; i++ ) {
for( *steps = 0; fabs(right - left) > 2 * epsilon; (*steps)++ ) {
mid = (right + left) / 2;
if( f(left) * f(mid) < 0 )
if( f(left) * (fmid = f(mid)) < 0 )
right = mid;
else if( f(right) * f(mid) < 0 )
else if( f(right) * fmid < 0 )
left = mid;
else
break;
}
*steps = i;
return mid;
}
......@@ -2,14 +2,14 @@
#include "func_ptr.h"
double regula_falsi(func_ptr f, double s, double t, double e,
int *steps, unsigned int m) {
int n, side = 0;
unsigned int *steps, unsigned int m) {
int side = 0;
double r, fr, fs = f(s), ft = f(t);
for( n = 0; n < m; n++ ) {
for( *steps = 0; *steps < m; (*steps)++ ) {
r = (fs * t - ft * s) / (fs - ft);
if( fabs(t - s) < e*fabs(t + s) )
if( fabs(t - s) < e * fabs(t + s) )
break;
fr = f(r);
......@@ -34,8 +34,6 @@ double regula_falsi(func_ptr f, double s, double t, double e,
break;
}
*steps = n;
return r;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment