From 7041cd13df0efcecd4223a11f5b83e67ffd36098 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 30 Apr 2024 12:46:26 +0200 Subject: [PATCH] functions: split off numeric functions --- inc/functions/num.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 inc/functions/num.php diff --git a/inc/functions/num.php b/inc/functions/num.php new file mode 100644 index 00000000..678312f3 --- /dev/null +++ b/inc/functions/num.php @@ -0,0 +1,33 @@ + $b) { + $a = $a+$b; + $b = $a-$b; + $a = $a-$b; + } + if ($b == (round($b / $a)) * $a) { + $gcd = $a; + } else { + for ($i = round($a / 2); $i; $i--) { + if ($a == round($a / $i) * $i && $b == round($b / $i) * $i) { + $gcd = $i; + $i = false; + } + } + } + + return $gcd; +} + +function fraction($numerator, $denominator, $sep) { + $gcf = hcf($numerator, $denominator); + $numerator = $numerator / $gcf; + $denominator = $denominator / $gcf; + + return "{$numerator}{$sep}{$denominator}"; +}