mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
0.5.5 features (#1151)
0.5.5 Disallow multiple `_` in a row in digits, e.g. `1__000`. #1138. Fixed toposort example. Struct/union members now correctly rejects members without storage size #1147. `math::pow` will now correctly promote integer arguments. `math::pow` will now correctly promote integer arguments. Added `new_aligned` and `alloc_aligned` functions to prevent accidental under-alignment when allocating simd. Pointer difference would fail where alignment != size (structs etc) #1150. Add test that overalignment actually works for lists. Fixed array calculation for npot2 vectors. Use native aligned alloc on Windows and POSIX. Deprecates "offset". Simplification of the Allocator interface.
This commit is contained in:
committed by
GitHub
parent
b7f4fd9074
commit
7ea3d230bb
15
test/test_suite/expressions/underscore_errors.c3
Normal file
15
test/test_suite/expressions/underscore_errors.c3
Normal file
@@ -0,0 +1,15 @@
|
||||
fn void main()
|
||||
{
|
||||
int a = 1___0; // #error: consecutive
|
||||
int a = 1_0;
|
||||
float b = 1_0.3__4; // #error: consecutive
|
||||
float b = 1_0.3_4;
|
||||
int a2 = 0x1___0; // #error: consecutive
|
||||
int a2 = 0x1_0;
|
||||
float b2 = 0x1_0.3__4; // #error: consecutive
|
||||
float b2 = 0x1_0.3_4;
|
||||
int a3 = 0b1___0; // #error: consecutive
|
||||
int a3 = 0b1_0;
|
||||
int a3 = 0o1___0; // #error: consecutive
|
||||
int a3 = 0o1_0;
|
||||
}
|
||||
7
test/test_suite/struct/struct_bad_member.c3
Normal file
7
test/test_suite/struct/struct_bad_member.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
struct Foo {
|
||||
void bar; // #error: Members cannot be of
|
||||
}
|
||||
|
||||
fn void main(String[] args) {
|
||||
Foo foo;
|
||||
}
|
||||
20
test/unit/regression/pointer_diff.c3
Normal file
20
test/unit/regression/pointer_diff.c3
Normal file
@@ -0,0 +1,20 @@
|
||||
import std;
|
||||
struct Foo
|
||||
{
|
||||
int a,b,c,d;
|
||||
}
|
||||
|
||||
fn void pointer_diff() @test
|
||||
{
|
||||
Foo* foo;
|
||||
isz offset = &foo[1] - &foo[0];
|
||||
assert(offset == 1);
|
||||
}
|
||||
|
||||
fn void pointer_add() @test
|
||||
{
|
||||
Foo* foo;
|
||||
Foo* bar = foo + 2;
|
||||
isz offset = bar - foo;
|
||||
assert(offset == 2);
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
module vecpointer @test;
|
||||
|
||||
fn void pointer_npot2_size()
|
||||
{
|
||||
int[<9>][3] a;
|
||||
assert((usz)&a[1] - (usz)&a[0] == 64);
|
||||
}
|
||||
|
||||
fn void pointer_add_sub_diff()
|
||||
{
|
||||
int[5] a;
|
||||
|
||||
@@ -4,6 +4,20 @@ import std::collections::list;
|
||||
def IntList = List(<int>);
|
||||
def PtrList = List(<void*>);
|
||||
|
||||
struct Overalign
|
||||
{
|
||||
double[<33>] x;
|
||||
}
|
||||
|
||||
fn void overaligned_type()
|
||||
{
|
||||
List(<Overalign>) l;
|
||||
Overalign y;
|
||||
for (int i = 0; i < 1000; i++) l.push(y);
|
||||
assert((usz)l.get_ref(2) - (usz)l.get_ref(1) == Overalign.sizeof);
|
||||
}
|
||||
|
||||
|
||||
fn void! delete_contains_index()
|
||||
{
|
||||
IntList test;
|
||||
|
||||
@@ -144,4 +144,24 @@ fn void! test_trunc() @test
|
||||
$assert @typeis(math::trunc(f), float);
|
||||
double[<5>] vec = { -123.9, 123.9, 0.9, -0.9, 0 };
|
||||
assert(math::trunc(vec) == double[<5>] { -123, 123, 0, 0, 0 });
|
||||
}
|
||||
|
||||
fn void! test_round_decimals() @test
|
||||
{
|
||||
double d = 0.532451241142;
|
||||
float d_f = 0.532451241142;
|
||||
assert(math::round_to_decimals(d, 2) == 0.53);
|
||||
assert(math::round_to_decimals(d, 5) == 0.53245);
|
||||
|
||||
assert(math::round_to_decimals(d_f, 2) == 0.53f);
|
||||
assert(math::round_to_decimals(d_f, 5) == 0.53245f);
|
||||
}
|
||||
|
||||
fn void! test() @test
|
||||
{
|
||||
double radians = math::deg_to_rad(45);
|
||||
float radians_f = (float)math::deg_to_rad(45);
|
||||
|
||||
assert(math::round_to_decimals(radians, 3) == 0.785);
|
||||
assert(math::round_to_decimals(radians_f, 3) == 0.785f);
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
module math_matrix @test;
|
||||
import std::math;
|
||||
|
||||
|
||||
|
||||
fn void test_mat4()
|
||||
{
|
||||
{|
|
||||
@@ -22,6 +20,69 @@ fn void test_mat4()
|
||||
Matrix4 value = { 56, 46, 36, 26, 152, 126, 100, 74, 56, 46, 36, 26, 152, 126, 100, 74 };
|
||||
assert(calc.m == value.m);
|
||||
|};
|
||||
|
||||
{|
|
||||
Matrix4 result = {
|
||||
0.988936, 0.000000, -0.148340, -0.988936,
|
||||
-0.014599, 0.995146, -0.097325, -2.970838,
|
||||
0.147620, 0.098414, 0.984136, -20.765262,
|
||||
0.000000, 0.000000, 0.000000, 1.000000
|
||||
};
|
||||
|
||||
Matrix4f result_f = {
|
||||
0.988936, 0.000000, -0.148340, -0.988936,
|
||||
-0.014599, 0.995146, -0.097325, -2.970838,
|
||||
0.147620, 0.098414, 0.984136, -20.765262,
|
||||
0.000000, 0.000000, 0.000000, 1.000000
|
||||
};
|
||||
|
||||
Matrix4 result_transposed = {
|
||||
0.988936, -0.014599, 0.147620, 0.000000,
|
||||
0.000000, 0.995146, 0.098414, 0.000000,
|
||||
-0.148340, -0.097325, 0.984136, 0.000000,
|
||||
-0.988936, -2.970838, -20.765262, 1.000000
|
||||
};
|
||||
|
||||
Matrix4f result_transposed_f = {
|
||||
0.988936, -0.014599, 0.147620, 0.000000,
|
||||
0.000000, 0.995146, 0.098414, 0.000000,
|
||||
-0.148340, -0.097325, 0.984136, 0.000000,
|
||||
-0.988936, -2.970838, -20.765262, 1.000000
|
||||
};
|
||||
|
||||
Matrix4 look_at = vector::matrix4_look_at({4.0, 5.0, 20.0}, {1.0, 3.0, 0.0}, {0.0, 1.0, 0.0});
|
||||
Matrix4f look_at_f = vector::matrix4f_look_at({4.0, 5.0, 20.0}, {1.0, 3.0, 0.0}, {0.0, 1.0, 0.0});
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])look_at.m, 4) == math::round_to_decimals((double[<16>])result.m, 4));
|
||||
assert(math::round_to_decimals((float[<16>])look_at_f.m, 4) == math::round_to_decimals((float[<16>])result_f.m, 4));
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])result_transposed.m, 4) == math::round_to_decimals((double[<16>])look_at.transpose().m, 4));
|
||||
assert(math::round_to_decimals((float[<16>])result_transposed_f.m, 4) == math::round_to_decimals((float[<16>])look_at_f.transpose().m, 4));
|
||||
|};
|
||||
|
||||
{|
|
||||
Matrix4 result = {
|
||||
1.857087, 0.000000, 0.000000,
|
||||
0.000000, 0.000000, 2.414214,
|
||||
0.000000, 0.000000, 0.000000, 0.000000,
|
||||
-1.000200, -0.200020, 0.000000, 0.000000,
|
||||
-1.000000, 0.000000
|
||||
};
|
||||
|
||||
Matrix4f result_f = {
|
||||
1.857087, 0.000000, 0.000000,
|
||||
0.000000, 0.000000, 2.414214,
|
||||
0.000000, 0.000000, 0.000000, 0.000000,
|
||||
-1.000200, -0.200020, 0.000000, 0.000000,
|
||||
-1.000000, 0.000000
|
||||
};
|
||||
|
||||
Matrix4 perspective = matrix4_perspective(math::deg_to_rad(45), 1.3, 0.1, 1000);
|
||||
Matrix4f perspective_f = matrix4f_perspective((float)math::deg_to_rad(45), 1.3, 0.1, 1000);
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])result.m, 4) == math::round_to_decimals((double[<16>])perspective.m, 4));
|
||||
assert(math::round_to_decimals((float[<16>])result_f.m, 4) == math::round_to_decimals((float[<16>])perspective_f.m, 4));
|
||||
|};
|
||||
}
|
||||
|
||||
|
||||
|
||||
38
test/unit/stdlib/math/quaternion.c3
Normal file
38
test/unit/stdlib/math/quaternion.c3
Normal file
@@ -0,0 +1,38 @@
|
||||
module math_quaternion @test;
|
||||
import std::math;
|
||||
|
||||
fn void test()
|
||||
{
|
||||
{|
|
||||
Quaternion rotation = QUATERNION_IDENTITY;
|
||||
Quaternionf rotation_f = QUATERNIONF_IDENTITY;
|
||||
assert(rotation.v == {0,0,0,1});
|
||||
assert(rotation.v == {0,0,0,1});
|
||||
|};
|
||||
|
||||
{|
|
||||
Quaternion rotation = QUATERNION_IDENTITY;
|
||||
Matrix4 identity_matrix = MATRIX4_IDENTITY;
|
||||
|
||||
Quaternionf rotation_f = QUATERNIONF_IDENTITY;
|
||||
Matrix4f identity_matrix_f = MATRIX4F_IDENTITY;
|
||||
|
||||
assert((double[<16>])rotation.to_matrix().m == (double[<16>])identity_matrix.m);
|
||||
assert((float[<16>])rotation_f.to_matrixf().m == (float[<16>])identity_matrix_f.m);
|
||||
|};
|
||||
|
||||
{|
|
||||
Matrix4 result = {
|
||||
0.428571, -0.285714, 0.857143, 0.000000,
|
||||
0.857143, 0.428571, -0.285714, 0.000000,
|
||||
-0.285714, 0.857143, 0.428571, 0.000000,
|
||||
0.000000, 0.000000, 0.000000, 1.000000
|
||||
};
|
||||
|
||||
Matrix4 rotation = Quaternion {0.5, 0.5, 0.5, 1}.to_matrix();
|
||||
Matrix4f rotation_f = Quaternionf {0.5, 0.5, 0.5, 1}.to_matrixf();
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])result.m, 2) == math::round_to_decimals((double[<16>])rotation.m, 2));
|
||||
assert(math::round_to_decimals((float[<16>])result.m, 2) == math::round_to_decimals((float[<16>])rotation_f.m, 2));
|
||||
|};
|
||||
}
|
||||
Reference in New Issue
Block a user