mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
[STDLIB] Add macro return types (#2487)
* add return types to macros where applicable * std::time::clock::now() -> clock::now()
This commit is contained in:
@@ -82,7 +82,7 @@ macro abs(x) => $$abs(x);
|
||||
@require values::@is_int(x) || values::@is_float(x) : "Expected an integer or floating point value"
|
||||
@require values::@is_int(y) || values::@is_float(y) : "Expected an integer or floating point value"
|
||||
*>
|
||||
macro is_approx(x, y, eps)
|
||||
macro bool is_approx(x, y, eps)
|
||||
{
|
||||
if (x == y) return true;
|
||||
if (is_nan(x) || is_nan(y)) return false;
|
||||
@@ -93,7 +93,7 @@ macro is_approx(x, y, eps)
|
||||
@require values::@is_int(x) || values::@is_float(x) : "Expected an integer or floating point value"
|
||||
@require values::@is_int(y) || values::@is_float(y) : "Expected an integer or floating point value"
|
||||
*>
|
||||
macro is_approx_rel(x, y, eps)
|
||||
macro bool is_approx_rel(x, y, eps)
|
||||
{
|
||||
if (x == y) return true;
|
||||
if (is_nan(x) || is_nan(y)) return false;
|
||||
@@ -132,7 +132,7 @@ macro atan2(x, y)
|
||||
@require @typematch(sinp, cosp) : "Expected sinp and cosp to have the same type"
|
||||
@require $defined(*sinp = x) : "Expected x and *sinp/*cosp to have the same type"
|
||||
*>
|
||||
macro sincos_ref(x, sinp, cosp)
|
||||
macro void sincos_ref(x, sinp, cosp)
|
||||
{
|
||||
$if $typeof(sinp) == float*:
|
||||
_sincosf(x, sinp, cosp);
|
||||
@@ -540,7 +540,7 @@ macro bool is_finite(x)
|
||||
<*
|
||||
@require values::@is_promotable_to_float(x) : `The input must be a float`
|
||||
*>
|
||||
macro is_nan(x)
|
||||
macro bool is_nan(x)
|
||||
{
|
||||
$switch $typeof(x):
|
||||
$case float:
|
||||
@@ -554,7 +554,7 @@ macro is_nan(x)
|
||||
<*
|
||||
@require values::@is_promotable_to_float(x) : `The input must be a float`
|
||||
*>
|
||||
macro is_inf(x)
|
||||
macro bool is_inf(x)
|
||||
{
|
||||
$switch $typeof(x):
|
||||
$case float:
|
||||
|
||||
@@ -140,7 +140,7 @@ macro ulong @int_to_long(#function) => (ulong)#function << 32 + #function;
|
||||
macro uint @short_to_int(#function) => (uint)#function << 16 + #function;
|
||||
macro ushort @char_to_short(#function) => (ushort)#function << 8 + #function;
|
||||
|
||||
macro @random_value_to_bytes(#function, char[] bytes)
|
||||
macro void @random_value_to_bytes(#function, char[] bytes)
|
||||
{
|
||||
var $byte_size = $sizeof(#function());
|
||||
usz len = bytes.len;
|
||||
@@ -174,7 +174,7 @@ interface Random
|
||||
}
|
||||
|
||||
|
||||
macro init_default_random() @private
|
||||
macro void init_default_random() @private
|
||||
{
|
||||
if (!default_random_initialized)
|
||||
{
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
module std::math::vector;
|
||||
import std::math;
|
||||
|
||||
macro double[<*>].sq_magnitude(self) => self.dot(self);
|
||||
macro float[<*>].sq_magnitude(self) => self.dot(self);
|
||||
macro double double[<*>].sq_magnitude(self) => self.dot(self);
|
||||
macro float float[<*>].sq_magnitude(self) => self.dot(self);
|
||||
|
||||
macro double[<*>].distance_sq(self, double[<*>] v2) => (self - v2).sq_magnitude();
|
||||
macro float[<*>].distance_sq(self, float[<*>] v2) => (self - v2).sq_magnitude();
|
||||
macro double double[<*>].distance_sq(self, double[<*>] v2) => (self - v2).sq_magnitude();
|
||||
macro float float[<*>].distance_sq(self, float[<*>] v2) => (self - v2).sq_magnitude();
|
||||
|
||||
macro float[<2>].transform(self, Matrix4f mat) => transform2(self, mat);
|
||||
macro float[<2>].rotate(self, float angle) => rotate(self, angle);
|
||||
macro float[<2>].angle(self, float[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x);
|
||||
macro float[<2>] float[<2>].transform(self, Matrix4f mat) => transform2(self, mat);
|
||||
macro float[<2>] float[<2>].rotate(self, float angle) => rotate(self, angle);
|
||||
macro float[<2>] float[<2>].angle(self, float[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x);
|
||||
|
||||
macro double[<2>].transform(self, Matrix4 mat) => transform2(self, mat);
|
||||
macro double[<2>].rotate(self, double angle) => rotate(self, angle);
|
||||
macro double[<2>].angle(self, double[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x);
|
||||
macro double[<2>] double[<2>].transform(self, Matrix4 mat) => transform2(self, mat);
|
||||
macro double[<2>] double[<2>].rotate(self, double angle) => rotate(self, angle);
|
||||
macro double[<2>] double[<2>].angle(self, double[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x);
|
||||
|
||||
macro float[<*>].clamp_mag(self, float min, float max) => clamp_magnitude(self, min, max);
|
||||
macro double[<*>].clamp_mag(self, double min, double max) => clamp_magnitude(self, min, max);
|
||||
macro float[<*>] float[<*>].clamp_mag(self, float min, float max) => clamp_magnitude(self, min, max);
|
||||
macro double[<*>] double[<*>].clamp_mag(self, double min, double max) => clamp_magnitude(self, min, max);
|
||||
|
||||
macro float[<*>].towards(self, float[<*>] target, float max_distance) => towards(self, target, max_distance);
|
||||
macro double[<*>].towards(self, double[<*>] target, double max_distance) => towards(self, target, max_distance);
|
||||
macro float[<*>] float[<*>].towards(self, float[<*>] target, float max_distance) => towards(self, target, max_distance);
|
||||
macro double[<*>] double[<*>].towards(self, double[<*>] target, double max_distance) => towards(self, target, max_distance);
|
||||
|
||||
fn float[<3>] float[<3>].cross(self, float[<3>] v2) => cross3(self, v2);
|
||||
fn double[<3>] double[<3>].cross(self, double[<3>] v2) => cross3(self, v2);
|
||||
|
||||
Reference in New Issue
Block a user