Add ft_sgn signum function
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 18 Jan 2024 09:56:04 +0000 (10:56 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 18 Jan 2024 09:56:04 +0000 (10:56 +0100)
Makefile
ft_math/ft_sgn.c [new file with mode: 0644]
inc/ft_math.h

index 431f293dd015ca0e8320d0e1bdd25f81836c0b8e..3fffc1f75e40a26cb207d5bb1f488e0f4ac91aed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,7 @@ SRCDIR := ft_gen ft_math ft_str ft_mem ft_io ft_check ft_conv ft_lst ft_arr
 SRCgen :=      ft_swap.c                               \
 
 SRCmath        :=      ft_abs.c                                \
+                       ft_sgn.c                                \
 
 SRCstr :=      ft_strncat_alloc.c              \
                        ft_strcmp.c                             \
diff --git a/ft_math/ft_sgn.c b/ft_math/ft_sgn.c
new file mode 100644 (file)
index 0000000..36c2a78
--- /dev/null
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_sgn.c                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/01/18 09:41:56 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/01/18 09:45:43 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "ft_math.h"
+
+int ft_sgn(int n)
+{
+       return ((n > 0) - (n < 0));
+}
+
+/*
+int    ft_sgn(int n)
+{
+       if (n > 0)
+               return (1);
+       if (n < 0)
+               return (-1);
+       return (0);
+}
+*/
index 9f0f6a74f2a00cdcd711cca6526739867db77197..657642e51f5fd280d4eaef6b8aa893286e83456d 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/09 12:19:15 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/12/09 15:13:41 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/01/18 09:44:29 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,5 +14,6 @@
 # define FT_MATH_H
 
 int            ft_abs(int n);
+int            ft_sgn(int n);
 
 #endif