Added vector dot functions. Comparison now yields bool vector. Cast between vector types.

This commit is contained in:
Christoffer Lerno
2022-12-16 17:15:28 +01:00
committed by Christoffer Lerno
parent 8008fb2c18
commit c339261d1e
16 changed files with 365 additions and 20 deletions

View File

@@ -0,0 +1,18 @@
import std::math;
fn void! vector_method_reduce() @test
{
float[<3>] x = { 1, 2.0, 4.0 };
int[<*>] y = { -23, 1, 4 };
assert(y.sum() == -18);
assert(y.product() == -92);
assert(y.max() == 4);
assert(y.and() == 0);
assert(y.xor() == -20);
assert(y.min() == -23);
assert(y.or() == -19);
assert(x.sum(1.2) - 8.2 < 0.000001);
assert(x.product(1.2) - 9.6 < 0.000001);
assert(x.min() == 1.0);
assert(x.max() == 4.0);
}

View File

@@ -1,11 +1,30 @@
import libc;
import std::io;
fn void! test_div() @test
fn void! test_conv() @test
{
float[<4>] y = { 1, 2, 3, 4 };
float[<4>] z = { 0, 2, 2, -100 };
int[<4>] w = { -1, 2, 3, 4 };
float[<4>] yy = w;
assert(yy == { -1.0, 2.0, 3.0, 4.0 });
ulong[<4>] ww = w;
assert(ww == { (ulong)-1, 2, 3, 4 });
int[<4>] g = (int[<4>])ww;
assert(g == w);
ww = (long[<4>])y;
assert(ww == { 1, 2, 3, 4 });
bool[<2>] b = { true, false };
int[<2>] gh = b;
assert(gh == { -1, 0 });
var $k = bool[<2>] { true, false };
var $gh = (int[<2>])$k;
$assert($gh[0] == -1);
var $gh2 = (char[<2>])$gh;
$assert($gh2[0] == 255);
b = (bool[<2>])gh;
assert(b == { true, false });
}
fn void! testf() @test
{
float[<4>] y = { 1, 2, 3, 4 };