]> Untitled Git - axy/ft/pushswap.git/commitdiff
Fractions
author= <=>
Thu, 18 Dec 2025 12:28:02 +0000 (13:28 +0100)
committer= <=>
Thu, 18 Dec 2025 12:28:02 +0000 (13:28 +0100)
frac.c [new file with mode: 0644]
pushswap.h

diff --git a/frac.c b/frac.c
new file mode 100644 (file)
index 0000000..449a18d
--- /dev/null
+++ b/frac.c
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   frac.c                                             :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: agilliar <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/12/18 13:20:12 by agilliar          #+#    #+#             */
+/*   Updated: 2025/12/18 13:27:56 by agilliar         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "pushswap.h"
+
+t_frac frac_new(size_t num, size_t den)
+{
+       t_frac  res;
+
+       res.num = num;
+       res.den = den;
+       return (res);
+}
+
+t_frac frac_mul(t_frac lhs, t_frac rhs)
+{
+       return (frac_new(lhs.num * rhs.num, lhs.den * rhs.den));
+}
+
+bool   frac_lte(t_frac lhs, t_frac rhs)
+{
+       return (lhs.num * rhs.den <= rhs.num * lhs.den);
+}
index e75801925cad50a2812ab1a4921619190e7c7629..b1c852046eb69e18f6be5b2a12e0a04f742706f3 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: clefrere <clefrere@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/12/02 11:02:44 by agilliar          #+#    #+#             */
-/*   Updated: 2025/12/16 20:18:54 by agilliar         ###   ########.fr       */
+/*   Updated: 2025/12/18 13:27:05 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -94,6 +94,12 @@ typedef struct s_slice
        const char      *ptr;
 }      t_slice;
 
+typedef struct s_frac
+{
+       size_t  num;
+       size_t  den;
+}      t_frac;
+
 void                   cheatexit(int errcode);
 void                   *cheatalloc(size_t len);
 
@@ -170,4 +176,8 @@ void                        algorithm_simple(const t_stacks *stacks, t_closure cb);
 void                   algorithm_complex(const t_stacks *stacks, t_closure cb);
 void                   algorithm_leafsort(const t_stacks *stacks, t_closure cb);
 
+t_frac                 frac_new(size_t num, size_t den);
+t_frac                 frac_mul(t_frac lhs, t_frac lhs);
+bool                   frac_lte(t_frac lhs, t_frac lhs);
+
 #endif