Compare commits
8 Commits
8edf428fed
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ac98cb1f5 | ||
|
|
71806cb923 | ||
|
|
e95f55c07f | ||
|
|
85423f4211 | ||
|
|
f662d7f750 | ||
|
|
de28530259 | ||
|
|
60c72d7560 | ||
|
|
ae9787ba6d |
3
Makefile
3
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 \
|
||||||
@@ -128,7 +128,6 @@ SRCS = ft_memset.c \
|
|||||||
ft_smaller.c \
|
ft_smaller.c \
|
||||||
ft_sign.c \
|
ft_sign.c \
|
||||||
ft_fsign.c \
|
ft_fsign.c \
|
||||||
ft_modf.c \
|
|
||||||
ft_pow.c \
|
ft_pow.c \
|
||||||
ft_sqrt.c \
|
ft_sqrt.c \
|
||||||
ft_round.c \
|
ft_round.c \
|
||||||
|
|||||||
@@ -130,10 +130,9 @@ int ft_greater(int a, int b);
|
|||||||
int ft_smaller(int a, int b);
|
int ft_smaller(int a, int b);
|
||||||
int ft_sign(int i);
|
int ft_sign(int i);
|
||||||
int ft_fsign(double i);
|
int ft_fsign(double i);
|
||||||
double ft_modf(double x, double *int_part);
|
|
||||||
double ft_pow(double base, int exponent);
|
double ft_pow(double base, int exponent);
|
||||||
double ft_round(double x);
|
double ft_round(double x);
|
||||||
int ft_sqrt(int 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);
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the absolute value of an int number
|
||||||
|
*/
|
||||||
|
|
||||||
int ft_abs(int n)
|
int ft_abs(int n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n *= -1;
|
n *= -1;
|
||||||
|
else if (n == 0)
|
||||||
|
n = 0; // for -0
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the absolute value of a double number
|
||||||
|
*/
|
||||||
|
|
||||||
double ft_fabs(double n)
|
double ft_fabs(double n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n *= -1;
|
n *= -1;
|
||||||
|
else if (n == 0)
|
||||||
|
n = 0; // for -0
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the absolute value of a long int number
|
||||||
|
*/
|
||||||
|
|
||||||
long int ft_labs(long int n)
|
long int ft_labs(long int n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n <= 0)
|
||||||
n *= -1;
|
n *= -1;
|
||||||
|
else if (n == 0)
|
||||||
|
n = 0; // for -0
|
||||||
return (n);
|
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"
|
#include "libft.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** return the square root of nb
|
* return the square root of nb
|
||||||
** or the integer value of it
|
* Newton–Raphson method : https://en.wikipedia.org/wiki/Newton%27s_method#Use_of_Newton's_method_to_compute_square_roots
|
||||||
*/
|
*/
|
||||||
int ft_sqrt(int nb)
|
double ft_sqrt(double x, double precision)
|
||||||
{
|
{
|
||||||
int i;
|
if (x < 0)
|
||||||
|
return -1; // handle negative numbers
|
||||||
|
if (x == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
i = 0;
|
// Newton-Raphson
|
||||||
while ((i*i) < nb)
|
double guess = x;
|
||||||
i++;
|
double prev_guess;
|
||||||
return (i);
|
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]));
|
ft_printf("--ft_strlen(srcs[%i]):%i--", i, ft_strlen(srcs[i]));
|
||||||
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')
|
// Check if buffer is large enough (include space for '\0')
|
||||||
if (total_len + 1 > dst_size)
|
if (total_len + 1 > dst_size)
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
/*
|
// /*
|
||||||
** return the square root of nb
|
// ** return the square root of nb
|
||||||
** or the integer value of it
|
// ** or the integer value of it
|
||||||
*/
|
// */
|
||||||
int ft_sqrt(int nb)
|
// int ft_sqrt(int nb)
|
||||||
{
|
// {
|
||||||
int i;
|
// int i;
|
||||||
|
|
||||||
i = 0;
|
// i = 0;
|
||||||
while ((i*i) < nb)
|
// while ((i*i) < nb)
|
||||||
i++;
|
// i++;
|
||||||
return (i);
|
// return (i);
|
||||||
}
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user