mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added compare_to as a standard macro.
This commit is contained in:
@@ -48,6 +48,20 @@ macro greater(a, b) @builtin
|
||||
$endswitch
|
||||
}
|
||||
|
||||
/**
|
||||
* @require types::is_comparable_value(a) && types::is_comparable_value(b)
|
||||
**/
|
||||
macro int compare_to(a, b) @builtin
|
||||
{
|
||||
$switch
|
||||
$case $defined(a.compare_to):
|
||||
return a.compare_to(b);
|
||||
$case $defined(a.less):
|
||||
return (int)b.less(a) - (int)a.less(b);
|
||||
$default:
|
||||
return (int)(a > b) - (int)(a < b);
|
||||
$endswitch
|
||||
}
|
||||
/**
|
||||
* @require types::is_comparable_value(a) && types::is_comparable_value(b)
|
||||
**/
|
||||
|
||||
@@ -131,7 +131,6 @@ macro sign(x)
|
||||
$endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @require values::@is_int(x) || values::@is_float(x) "Expected an integer or floating point value"
|
||||
* @checked x + y
|
||||
|
||||
Reference in New Issue
Block a user