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

Fixed unsigned integer comparison problem.

parent 0c91e4d7
#include "func_ptr.h" #include "func_ptr.h"
double bisec(func_ptr f, double left, double right, double epsilon, unsigned int *steps) { double bisec(func_ptr f, double left, double right,
int i; double epsilon, unsigned int *steps) {
double mid; 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; mid = (right + left) / 2;
if( f(left) * f(mid) < 0 ) if( f(left) * (fmid = f(mid)) < 0 )
right = mid; right = mid;
else if( f(right) * f(mid) < 0 ) else if( f(right) * fmid < 0 )
left = mid; left = mid;
else else
break; break;
} }
*steps = i;
return mid; return mid;
} }
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
#include "func_ptr.h" #include "func_ptr.h"
double regula_falsi(func_ptr f, double s, double t, double e, double regula_falsi(func_ptr f, double s, double t, double e,
int *steps, unsigned int m) { unsigned int *steps, unsigned int m) {
int n, side = 0; int side = 0;
double r, fr, fs = f(s), ft = f(t); 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); r = (fs * t - ft * s) / (fs - ft);
if( fabs(t - s) < e*fabs(t + s) ) if( fabs(t - s) < e * fabs(t + s) )
break; break;
fr = f(r); fr = f(r);
...@@ -34,8 +34,6 @@ double regula_falsi(func_ptr f, double s, double t, double e, ...@@ -34,8 +34,6 @@ double regula_falsi(func_ptr f, double s, double t, double e,
break; break;
} }
*steps = n;
return r; 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