Compare commits
3 Commits
85423f4211
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ac98cb1f5 | ||
|
|
71806cb923 | ||
|
|
e95f55c07f |
2
Makefile
2
Makefile
@@ -12,7 +12,7 @@ _DEP = libft.h
|
|||||||
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
|
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
|
||||||
|
|
||||||
CFLAGS = -I$(IDIR)
|
CFLAGS = -I$(IDIR)
|
||||||
CFLAGS += -Wall -Wextra -Werror -g3
|
CFLAGS += -Wall -Wextra -Werror -g
|
||||||
|
|
||||||
SRCS = ft_memset.c \
|
SRCS = ft_memset.c \
|
||||||
ft_bzero.c \
|
ft_bzero.c \
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ int ft_sign(int i);
|
|||||||
int ft_fsign(double i);
|
int ft_fsign(double i);
|
||||||
double ft_pow(double base, int exponent);
|
double ft_pow(double base, int exponent);
|
||||||
double ft_round(double x);
|
double ft_round(double x);
|
||||||
double ft_sqrt(double i);
|
double ft_sqrt(double i, double precision);
|
||||||
void ft_free_tab(char **tab);
|
void ft_free_tab(char **tab);
|
||||||
|
|
||||||
int ft_arrint(int *intarr, int comp, size_t size);
|
int ft_arrint(int *intarr, int comp, size_t size);
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ long long ft_atoll_superscript(const char *str)
|
|||||||
int digit;
|
int digit;
|
||||||
if (superscript_size == 2)
|
if (superscript_size == 2)
|
||||||
{
|
{
|
||||||
// ² (U+00B2) or ³ (U+00B3)
|
// ¹ (U+00B9), ² (U+00B2), or ³ (U+00B3)
|
||||||
if ((uint8_t)str[i + 1] == 0xB2)
|
if ((uint8_t)str[i + 1] == 0xB9)
|
||||||
|
digit = 1;
|
||||||
|
else if ((uint8_t)str[i + 1] == 0xB2)
|
||||||
digit = 2;
|
digit = 2;
|
||||||
else if ((uint8_t)str[i + 1] == 0xB3)
|
else if ((uint8_t)str[i + 1] == 0xB3)
|
||||||
digit = 3;
|
digit = 3;
|
||||||
|
|||||||
@@ -4,17 +4,13 @@
|
|||||||
* return the square root of nb
|
* return the square root of nb
|
||||||
* Newton–Raphson method : https://en.wikipedia.org/wiki/Newton%27s_method#Use_of_Newton's_method_to_compute_square_roots
|
* Newton–Raphson 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)
|
if (x < 0)
|
||||||
return -1; // handle negative numbers
|
return -1; // handle negative numbers
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
precision = 0.00001;
|
|
||||||
|
|
||||||
// Newton-Raphson
|
// Newton-Raphson
|
||||||
double guess = x;
|
double guess = x;
|
||||||
double prev_guess;
|
double prev_guess;
|
||||||
@@ -22,11 +18,11 @@ double ft_sqrt(double x)
|
|||||||
{
|
{
|
||||||
prev_guess = guess;
|
prev_guess = guess;
|
||||||
guess = (guess + x / guess) / 2.0;
|
guess = (guess + x / guess) / 2.0;
|
||||||
} while (prev_guess - guess > precision);
|
} while (ft_fabs(prev_guess - guess) > precision);
|
||||||
return guess;
|
return guess;
|
||||||
|
|
||||||
// // binary search
|
// // binary search
|
||||||
// double low = 0
|
// double low = 0;
|
||||||
// double high = x;
|
// double high = x;
|
||||||
// double mid;
|
// double mid;
|
||||||
// while (high - low > precision)
|
// while (high - low > precision)
|
||||||
|
|||||||
Reference in New Issue
Block a user