Add ft_min and ft_max functions for int and size_t
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 23 Feb 2024 08:08:45 +0000 (09:08 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 23 Feb 2024 08:08:45 +0000 (09:08 +0100)
Makefile
ft_math/ft_max.c [new file with mode: 0644]
ft_math/ft_min.c [new file with mode: 0644]
inc/ft_math.h

index 3fffc1f75e40a26cb207d5bb1f488e0f4ac91aed..c49039e6029c24e295422d32b60df3f1a4eaaf0c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,8 @@ SRCgen        :=      ft_swap.c                               \
 
 SRCmath        :=      ft_abs.c                                \
                        ft_sgn.c                                \
+                       ft_max.c                                \
+                       ft_min.c                                \
 
 SRCstr :=      ft_strncat_alloc.c              \
                        ft_strcmp.c                             \
diff --git a/ft_math/ft_max.c b/ft_math/ft_max.c
new file mode 100644 (file)
index 0000000..076c6e8
--- /dev/null
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_max.c                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/02/22 14:29:48 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/02/23 08:57:26 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_math.h"
+#include <stddef.h>
+
+int    ft_max(int a, int b)
+{
+       if (a > b)
+               return (a);
+       return (b);
+}
+
+size_t ft_maxs(size_t a, size_t b)
+{
+       if (a > b)
+               return (a);
+       return (b);
+}
diff --git a/ft_math/ft_min.c b/ft_math/ft_min.c
new file mode 100644 (file)
index 0000000..d09f05e
--- /dev/null
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_min.c                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/02/23 08:58:39 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/02/23 08:59:40 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_math.h"
+#include <stddef.h>
+
+int    ft_min(int a, int b)
+{
+       if (a < b)
+               return (a);
+       return (b);
+}
+
+size_t ft_mins(size_t a, size_t b)
+{
+       if (a < b)
+               return (a);
+       return (b);
+}
index 657642e51f5fd280d4eaef6b8aa893286e83456d..6c272f48aa50e938ac8da3c2256e210567d32ff2 100644 (file)
@@ -6,14 +6,22 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/09 12:19:15 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/01/18 09:44:29 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/02/23 09:01:20 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef FT_MATH_H
 # define FT_MATH_H
 
+# include <stddef.h>
+
 int            ft_abs(int n);
 int            ft_sgn(int n);
 
+int            ft_max(int a, int b);
+size_t ft_maxs(size_t a, size_t b);
+
+int            ft_min(int a, int b);
+size_t ft_mins(size_t a, size_t b);
+
 #endif