Change smth
This commit is contained in:
parent
4d61d7f22a
commit
1053f8e3c2
22 changed files with 93 additions and 297 deletions
|
@ -1,5 +1,4 @@
|
|||
#include "solve.h"
|
||||
#include "status.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
@ -7,14 +6,13 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
status t3_solve (
|
||||
int t3_solve (
|
||||
double (*f) (double),
|
||||
double a, double b,
|
||||
double eps, int m, double *x, int *m_it
|
||||
double eps, int m, double *x
|
||||
) {
|
||||
int it = 0;
|
||||
uint64_t bits;
|
||||
status ret = SUCCESS;
|
||||
double c = DBL_MAX, y, y_a = f(a), y_b = f(b);
|
||||
bool sgn_a, sgn_b, sgn_c;
|
||||
|
||||
|
@ -26,20 +24,20 @@ status t3_solve (
|
|||
if (fabs(y_a) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = a;
|
||||
return SUCCESS;
|
||||
return 1;
|
||||
} if (fabs(y_b) - eps < DBL_EPSILON)
|
||||
{
|
||||
*x = b;
|
||||
return SUCCESS;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sgn_a == sgn_b)
|
||||
{
|
||||
*x = DBL_MAX;
|
||||
return MORE_ONE_ROOT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (it = 0; it < m; ++it)
|
||||
for (it = 1; it <= m; ++it)
|
||||
{
|
||||
c = a - ((a - b) / (y_a - y_b)) * y_a;
|
||||
y = f(c);
|
||||
|
@ -48,18 +46,13 @@ status t3_solve (
|
|||
sgn_c = (bits >> 63) & 1;
|
||||
|
||||
if ((c - a < DBL_EPSILON) || (c - b > DBL_EPSILON))
|
||||
{
|
||||
ret = BOUNDARIES;
|
||||
it = m+1;
|
||||
else if (fabs(y) - eps < DBL_EPSILON)
|
||||
break;
|
||||
} else if (fabs(y) - eps < DBL_EPSILON)
|
||||
{
|
||||
ret = SUCCESS;
|
||||
break;
|
||||
} else if (sgn_c == sgn_a)
|
||||
else if (sgn_c == sgn_a)
|
||||
{
|
||||
a = c;
|
||||
y_a = y;
|
||||
|
||||
} else if (sgn_c == sgn_b)
|
||||
{
|
||||
b = c;
|
||||
|
@ -67,12 +60,11 @@ status t3_solve (
|
|||
}
|
||||
}
|
||||
|
||||
if (it >= m)
|
||||
ret = RUN_TIME;
|
||||
if (it > m)
|
||||
it = -1;
|
||||
|
||||
*x = c;
|
||||
*m_it = it;
|
||||
|
||||
return ret;
|
||||
return it;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue