29 lines
362 B
C
29 lines
362 B
C
#include "config.h"
|
|
|
|
double positive (double x) {
|
|
|
|
if (x > 0.0)
|
|
return x;
|
|
else
|
|
return 0.0 - x;
|
|
|
|
}
|
|
|
|
double sqrt (double a) {
|
|
|
|
double x_old = 1.0, x_new = 0.5;
|
|
|
|
if (a > 0.0) {
|
|
do {
|
|
|
|
x_old = x_new;
|
|
x_new = ((a / x_old) + x_old) / 2.0;
|
|
|
|
} while (positive(x_old - x_new) > MY_DELTA_MAX);
|
|
|
|
return x_new;
|
|
|
|
} else exit(1);
|
|
|
|
}
|