Added max and min macros to builtin_comparison module.

This commit is contained in:
Dmitry Atamanov
2022-10-04 20:08:01 +05:00
committed by Christoffer Lerno
parent f5a1894876
commit 1d39fc475f
4 changed files with 51 additions and 11 deletions

View File

@@ -74,3 +74,36 @@ macro bool equals(a, b) @builtin
return a == b;
$endif;
}
macro min(x, ...) @builtin
{
$if ($vacount == 1):
return less(x, $vaarg(0)) ? x : $vaarg(0);
$else:
$typeof(x) result = x;
$for (var $i = 0; $i < $vacount; $i++):
if (less($vaarg($i), result))
{
result = $vaarg($i);
}
$endfor;
return result;
$endif;
}
macro max(x, ...) @builtin
{
$if ($vacount == 1):
return greater(x, $vaarg(0)) ? x : $vaarg(0);
$else:
$typeof(x) result = x;
$for (var $i = 0; $i < $vacount; $i++):
if (greater($vaarg($i), result))
{
result = $vaarg($i);
}
$endfor;
return result;
$endif;
}

View File

@@ -71,17 +71,6 @@ const QUAD_EPSILON = 1.92592994438723585305597794258492732e-34;
define Complex32 = Complex<float>;
define Complex64 = Complex<double>;
macro max(x, y) @builtin
{
return x > y ? x : y;
}
macro min(x, y) @builtin
{
return x < y ? x : y;
}
fn double log10(double x) @inline
{
return $$log10(x);