mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added max and min macros to builtin_comparison module.
This commit is contained in:
committed by
Christoffer Lerno
parent
f5a1894876
commit
1d39fc475f
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
9
test/test_suite/stdlib/minmax.c3
Normal file
9
test/test_suite/stdlib/minmax.c3
Normal file
@@ -0,0 +1,9 @@
|
||||
import std::io;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
io::printfln("min(-1, 1) == %s", min(-1, 1));
|
||||
io::printfln("max(-1, 1) == %s", max(-1, 1));
|
||||
io::printfln("min(-1, 0, 1) == %s", min(-1, 0, 1));
|
||||
io::printfln("max(-1, 0, 1) == %s", max(-1, 0, 1));
|
||||
}
|
||||
9
test/test_suite2/stdlib/minmax.c3
Normal file
9
test/test_suite2/stdlib/minmax.c3
Normal file
@@ -0,0 +1,9 @@
|
||||
import std::io;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
io::printfln("min(-1, 1) == %s", min(-1, 1));
|
||||
io::printfln("max(-1, 1) == %s", max(-1, 1));
|
||||
io::printfln("min(-1, 0, 1) == %s", min(-1, 0, 1));
|
||||
io::printfln("max(-1, 0, 1) == %s", max(-1, 0, 1));
|
||||
}
|
||||
Reference in New Issue
Block a user