update ft_sqrt with precision

This commit is contained in:
hugogogo
2026-05-14 13:53:09 +02:00
parent 85423f4211
commit e95f55c07f
2 changed files with 2 additions and 6 deletions

View File

@@ -132,7 +132,7 @@ int ft_sign(int i);
int ft_fsign(double i);
double ft_pow(double base, int exponent);
double ft_round(double x);
double ft_sqrt(double i);
double ft_sqrt(double i, double precision);
void ft_free_tab(char **tab);
int ft_arrint(int *intarr, int comp, size_t size);

View File

@@ -4,17 +4,13 @@
* return the square root of nb
* NewtonRaphson method : https://en.wikipedia.org/wiki/Newton%27s_method#Use_of_Newton's_method_to_compute_square_roots
*/
double ft_sqrt(double x)
double ft_sqrt(double x, double precision)
{
double precision;
if (x < 0)
return -1; // handle negative numbers
if (x == 0)
return 0;
precision = 0.00001;
// Newton-Raphson
double guess = x;
double prev_guess;