From 6879b46aee32735c2a6091b582789923c942485a Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:41:56 +0200 Subject: [PATCH 01/10] feat(math/abs): adding ft_abs function - Return the absolute value --- math/ft_abs.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 math/ft_abs.c diff --git a/math/ft_abs.c b/math/ft_abs.c new file mode 100644 index 0000000..e3beef1 --- /dev/null +++ b/math/ft_abs.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/17 16:37:35 by rparodi #+# #+# */ +/* Updated: 2025/09/17 16:39:43 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +uint32_t ft_abs(int64_t value) +{ + if (value < 0) + return (-value); + else + return (value); +} From 82c445502b2a44b71971c9806ada190fe951d80e Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:42:17 +0200 Subject: [PATCH 02/10] feat(math/ft_max): adding ft_max - Using the bitwise for fun :eyes: --- math/ft_max.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 math/ft_max.c diff --git a/math/ft_max.c b/math/ft_max.c new file mode 100644 index 0000000..6d9c1d7 --- /dev/null +++ b/math/ft_max.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/17 16:23:22 by rparodi #+# #+# */ +/* Updated: 2025/09/17 16:24:17 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +uint32_t ft_max(uint32_t x, uint32_t y) +{ + return (x ^ ((x ^ y) & -(x < y))); +} From d8ac7d2b88a8865bcfbfe9eac308041b4dfa59e9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:42:24 +0200 Subject: [PATCH 03/10] feat(math/ft_min): adding ft_min - Using the bitwise for fun :eyes: --- math/ft_min.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 math/ft_min.c diff --git a/math/ft_min.c b/math/ft_min.c new file mode 100644 index 0000000..09d0fe5 --- /dev/null +++ b/math/ft_min.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_min.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/17 16:20:11 by rparodi #+# #+# */ +/* Updated: 2025/09/17 16:25:27 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +uint32_t ft_min(uint32_t x, uint32_t y) +{ + return (y ^ ((x ^ y) & -(x < y))); +} From c27526bc246e394d25832484e266fd53cd0ed040 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:42:42 +0200 Subject: [PATCH 04/10] feat(math/power): adding a function to calculate power --- math/ft_power.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 math/ft_power.c diff --git a/math/ft_power.c b/math/ft_power.c new file mode 100644 index 0000000..5a15e5d --- /dev/null +++ b/math/ft_power.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/17 16:08:00 by rparodi #+# #+# */ +/* Updated: 2025/09/17 16:12:39 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +uint64_t ft_power(uint64_t base, uint64_t exponent) +{ + uint64_t i; + uint64_t result; + + i = 0; + result = 1; + if (exponent == 0) + return (1); + while (i < exponent) + { + result *= base; + i++; + } + return (result); +} From 62dec89863359b6df166607a16192d7cadd49c49 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:43:00 +0200 Subject: [PATCH 05/10] feat(math/sqrt): adding a function to calculate square root --- math/ft_sqrt.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 math/ft_sqrt.c diff --git a/math/ft_sqrt.c b/math/ft_sqrt.c new file mode 100644 index 0000000..2570115 --- /dev/null +++ b/math/ft_sqrt.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sqrt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/17 16:30:27 by rparodi #+# #+# */ +/* Updated: 2025/09/17 16:37:00 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +uint64_t ft_sqrt(uint64_t nb) +{ + uint64_t i; + + i = 1; + while ((i * i) <= nb && i <= 4294967296) + { + if ((i * i) == nb) + return (i); + i++; + } + return (0); +} From b5f2f370bf694ab7fe57ff888423707f86573a5a Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:43:22 +0200 Subject: [PATCH 06/10] build: adding math part on the makefile --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cb9d296..1b32f0e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2025/09/05 16:21:13 by rparodi ### ########.fr # +# Updated: 2025/09/17 16:39:23 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -49,6 +49,11 @@ SRC = char/ft_isalnum.c \ list/ft_lstmap.c \ list/ft_lstnew.c \ list/ft_lstsize.c \ + math/ft_max.c \ + math/ft_min.c \ + math/ft_power.c \ + math/ft_abs.c \ + math/ft_sqrt.c \ memory/ft_bzero.c \ memory/ft_calloc.c \ memory/ft_memchr.c \ From 574c470a1c67f75e0b36d69077091494025b4921 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:45:20 +0200 Subject: [PATCH 07/10] feat(math): adding the header for math library --- includes/math.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 includes/math.h diff --git a/includes/math.h b/includes/math.h new file mode 100644 index 0000000..06f742b --- /dev/null +++ b/includes/math.h @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* math.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/09/17 16:14:25 by rparodi #+# #+# */ +/* Updated: 2025/09/17 16:44:55 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MATH_H +# define MATH_H + +# include + +/** + * @brief Perform a power calculation + * + * @param base The element to calculate the power + * @param exponent The power to calculate + * @return The result of the operation + */ +uint64_t ft_power(uint64_t base, uint64_t exponent); + +/** + * @brief Select the maximum of the two parameters + * + * @param x First element + * @param y Second element + * @return The maximum of the two parameters + */ +uint32_t ft_min(uint32_t x, uint32_t y); + +/** + * @brief Select the minimum of the two parameters + * + * @param x First element + * @param y Second element + * @return The minimum of the two parameters + */ +uint32_t ft_min(uint32_t x, uint32_t y); + +/** + * @brief Perform a Root sqare calculation + * + * @param number The element to calculate + * @return The square root of the parameters + */ +uint64_t ft_sqrt(uint64_t number); + +#endif From 90d32dca61cb596198b6b617c338f7824ce19e95 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:45:41 +0200 Subject: [PATCH 08/10] style(math/sqrt): changing the parameter name to be clearer --- math/ft_sqrt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/math/ft_sqrt.c b/math/ft_sqrt.c index 2570115..477c124 100644 --- a/math/ft_sqrt.c +++ b/math/ft_sqrt.c @@ -6,21 +6,21 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/17 16:30:27 by rparodi #+# #+# */ -/* Updated: 2025/09/17 16:37:00 by rparodi ### ########.fr */ +/* Updated: 2025/09/17 16:44:28 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include #include -uint64_t ft_sqrt(uint64_t nb) +uint64_t ft_sqrt(uint64_t number) { uint64_t i; i = 1; - while ((i * i) <= nb && i <= 4294967296) + while ((i * i) <= number && i <= 4294967296) { - if ((i * i) == nb) + if ((i * i) == number) return (i); i++; } From faf72b58959fba51701e1868e79e0f56ac9ce03c Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:46:13 +0200 Subject: [PATCH 09/10] refactor(test/convert): norming the test of itoa --- test/convert/test_itoa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/convert/test_itoa.c b/test/convert/test_itoa.c index b84d08b..47303a1 100644 --- a/test/convert/test_itoa.c +++ b/test/convert/test_itoa.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/08 10:09:06 by rparodi ### ########.fr */ +/* Updated: 2025/09/17 16:40:41 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ int main(void) { - const int integer[] = {0, 42, -42, +-42, -2147483648, 2147483647, 13, 7}; + const int integer[] = {0, 42, -42, + -42, -2147483648, 2147483647, 13, 7}; char result[1024]; size_t i; From 801634c6dc9a737c60961fdf273a78208ba417b5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 17 Sep 2025 16:47:00 +0200 Subject: [PATCH 10/10] refactor(convert): norming the convert header - ft_atou was not aligned --- includes/convert.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/convert.h b/includes/convert.h index d7867c3..6f57322 100644 --- a/includes/convert.h +++ b/includes/convert.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 14:57:24 by rparodi #+# #+# */ -/* Updated: 2025/09/08 10:17:01 by rparodi ### ########.fr */ +/* Updated: 2025/09/17 16:40:58 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,7 @@ int ft_atoi(const char *nptr); * @param nptr the string that will be converted * @return The unsigned long long on the string */ -size_t ft_atou(const char *nptr); +size_t ft_atou(const char *nptr); /** * @brief Converts string to long long integer