Compare commits
9 Commits
3cf0b6ecb9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ac98cb1f5 | ||
|
|
71806cb923 | ||
|
|
e95f55c07f | ||
|
|
85423f4211 | ||
|
|
f662d7f750 | ||
|
|
de28530259 | ||
|
|
60c72d7560 | ||
|
|
ae9787ba6d | ||
|
|
8edf428fed |
5
Makefile
5
Makefile
@@ -12,7 +12,7 @@ _DEP = libft.h
|
||||
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
|
||||
|
||||
CFLAGS = -I$(IDIR)
|
||||
CFLAGS += -Wall -Wextra -Werror -g3
|
||||
CFLAGS += -Wall -Wextra -Werror -g
|
||||
|
||||
SRCS = ft_memset.c \
|
||||
ft_bzero.c \
|
||||
@@ -127,8 +127,7 @@ SRCS = ft_memset.c \
|
||||
ft_greater.c \
|
||||
ft_smaller.c \
|
||||
ft_sign.c \
|
||||
ft_sign_f.c \
|
||||
ft_modf.c \
|
||||
ft_fsign.c \
|
||||
ft_pow.c \
|
||||
ft_sqrt.c \
|
||||
ft_round.c \
|
||||
|
||||
@@ -129,11 +129,10 @@ double ft_fabs(double n);
|
||||
int ft_greater(int a, int b);
|
||||
int ft_smaller(int a, int b);
|
||||
int ft_sign(int i);
|
||||
int ft_sign_f(double i);
|
||||
double ft_modf(double x, double *int_part);
|
||||
int ft_fsign(double i);
|
||||
double ft_pow(double base, int exponent);
|
||||
double ft_round(double x);
|
||||
int ft_sqrt(int i);
|
||||
double ft_sqrt(double i, double precision);
|
||||
void ft_free_tab(char **tab);
|
||||
|
||||
int ft_arrint(int *intarr, int comp, size_t size);
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* returns the absolute value of an int number
|
||||
*/
|
||||
|
||||
int ft_abs(int n)
|
||||
{
|
||||
if (n < 0)
|
||||
n *= -1;
|
||||
else if (n == 0)
|
||||
n = 0; // for -0
|
||||
return (n);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,10 @@ long long ft_atoll_superscript(const char *str)
|
||||
int digit;
|
||||
if (superscript_size == 2)
|
||||
{
|
||||
// ² (U+00B2) or ³ (U+00B3)
|
||||
if ((uint8_t)str[i + 1] == 0xB2)
|
||||
// ¹ (U+00B9), ² (U+00B2), or ³ (U+00B3)
|
||||
if ((uint8_t)str[i + 1] == 0xB9)
|
||||
digit = 1;
|
||||
else if ((uint8_t)str[i + 1] == 0xB2)
|
||||
digit = 2;
|
||||
else if ((uint8_t)str[i + 1] == 0xB3)
|
||||
digit = 3;
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* returns the absolute value of a double number
|
||||
*/
|
||||
|
||||
double ft_fabs(double n)
|
||||
{
|
||||
if (n < 0)
|
||||
n *= -1;
|
||||
else if (n == 0)
|
||||
n = 0; // for -0
|
||||
return (n);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "libft.h"
|
||||
|
||||
int ft_sign_f(double i)
|
||||
int ft_fsign(double i)
|
||||
{
|
||||
if (i < 0)
|
||||
return (-1);
|
||||
else if (i == 0)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* returns the absolute value of a long int number
|
||||
*/
|
||||
|
||||
long int ft_labs(long int n)
|
||||
{
|
||||
if (n < 0)
|
||||
if (n <= 0)
|
||||
n *= -1;
|
||||
else if (n == 0)
|
||||
n = 0; // for -0
|
||||
return (n);
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* Splits a double into its integer and fractional parts,
|
||||
* it returns the fractional part,
|
||||
* and stores the integer part in the in_part param (if not null)
|
||||
* e.g.:
|
||||
* -3.7 → -3.0 and -0.7 (returns -0.7)
|
||||
*/
|
||||
double ft_modf(double x, double *int_part)
|
||||
{
|
||||
// extract the integer part by casting to long long
|
||||
long long integer = (long long)x;
|
||||
if (int_part != NULL)
|
||||
{
|
||||
*int_part = (double)integer;
|
||||
}
|
||||
|
||||
// compute the fractional part
|
||||
double frac_part = x - *int_part;
|
||||
|
||||
return frac_part;
|
||||
}
|
||||
@@ -1,15 +1,37 @@
|
||||
#include "libft.h"
|
||||
|
||||
/*
|
||||
** return the square root of nb
|
||||
** or the integer value of it
|
||||
*/
|
||||
int ft_sqrt(int 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
|
||||
*/
|
||||
double ft_sqrt(double x, double precision)
|
||||
{
|
||||
int i;
|
||||
if (x < 0)
|
||||
return -1; // handle negative numbers
|
||||
if (x == 0)
|
||||
return 0;
|
||||
|
||||
i = 0;
|
||||
while ((i*i) < nb)
|
||||
i++;
|
||||
return (i);
|
||||
// Newton-Raphson
|
||||
double guess = x;
|
||||
double prev_guess;
|
||||
do
|
||||
{
|
||||
prev_guess = guess;
|
||||
guess = (guess + x / guess) / 2.0;
|
||||
} while (ft_fabs(prev_guess - guess) > precision);
|
||||
return guess;
|
||||
|
||||
// // binary search
|
||||
// double low = 0;
|
||||
// double high = x;
|
||||
// double mid;
|
||||
// while (high - low > precision)
|
||||
// {
|
||||
// mid = (low + high) / 2.0;
|
||||
// if (mid * mid < x)
|
||||
// low = mid;
|
||||
// else
|
||||
// high = mid;
|
||||
// }
|
||||
// return (low + high) / 2.0;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ size_t ft_strjoin_static(char *dst, size_t dst_size, const char **srcs, size_t n
|
||||
ft_printf("--ft_strlen(srcs[%i]):%i--", i, ft_strlen(srcs[i]));
|
||||
i++;
|
||||
}
|
||||
ft_printf("{dst_size:%li,srcs[0]:%s,srcs[1]:%s,total_len:%i}", dst_size, srcs[0], srcs[1], total_len); // debug
|
||||
|
||||
// Check if buffer is large enough (include space for '\0')
|
||||
if (total_len + 1 > dst_size)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "libft.h"
|
||||
|
||||
/*
|
||||
** return the square root of nb
|
||||
** or the integer value of it
|
||||
*/
|
||||
int ft_sqrt(int nb)
|
||||
{
|
||||
int i;
|
||||
// /*
|
||||
// ** return the square root of nb
|
||||
// ** or the integer value of it
|
||||
// */
|
||||
// int ft_sqrt(int nb)
|
||||
// {
|
||||
// int i;
|
||||
|
||||
i = 0;
|
||||
while ((i*i) < nb)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
// i = 0;
|
||||
// while ((i*i) < nb)
|
||||
// i++;
|
||||
// return (i);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user