Change smth

This commit is contained in:
AZEN-SGG 2025-05-02 04:20:19 +03:00
parent 4d61d7f22a
commit 1053f8e3c2
22 changed files with 93 additions and 297 deletions

View file

@ -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 t1_solve (
int t1_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 t1_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 + b) * 0.5;
y = f(c);
@ -48,14 +46,10 @@ status t1_solve (
sgn_c = (bits >> 63) & 1;
if (fabs(y) - eps < DBL_EPSILON)
{
ret = SUCCESS;
break;
} else if ((fabs(c - a) < DBL_EPSILON) || (fabs(c - b) < DBL_EPSILON))
{
ret = HIGH_ERROR;
break;
} else if (sgn_c == sgn_a)
else if ((fabs(c - a) < DBL_EPSILON) || (fabs(c - b) < DBL_EPSILON))
it = m+1;
else if (sgn_c == sgn_a)
{
a = c;
y_a = y;
@ -66,12 +60,11 @@ status t1_solve (
}
}
if (it >= m)
ret = RUN_TIME;
if (it > m)
it = -1;
*x = c;
*m_it = it;
return ret;
return it;
}