Initial refactor of functions.php

This commit is contained in:
Zankaria
2024-01-31 15:32:22 +01:00
parent f45bc768fe
commit 3baa68c7b6
9 changed files with 680 additions and 645 deletions

33
inc/functions/math.php Normal file
View File

@@ -0,0 +1,33 @@
<?php // Math related functions
defined('TINYBOARD') or exit;
// Highest common factor
function hcf($a, $b){
$gcd = 1;
if ($a>$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}";
}