diff --git a/lib/std/math/math_matrix.c3 b/lib/std/math/math_matrix.c3 index 8129fd4d0..11a9978c1 100644 --- a/lib/std/math/math_matrix.c3 +++ b/lib/std/math/math_matrix.c3 @@ -197,7 +197,7 @@ fn Real Matrix4x4.determinant(&self) fn Matrix2x2 Matrix2x2.adjoint(&self) { - return { self.m00, -self.m01, -self.m10, self.m11 }; + return { self.m11, -self.m01, -self.m10, self.m00 }; } fn Matrix3x3 Matrix3x3.adjoint(&self) diff --git a/test/unit/stdlib/math/matrix.c3 b/test/unit/stdlib/math/matrix.c3 index 97bb966d3..7eae62d0f 100644 --- a/test/unit/stdlib/math/matrix.c3 +++ b/test/unit/stdlib/math/matrix.c3 @@ -106,8 +106,17 @@ fn void test_mat2() assert(calc.m == value.m); } +fn void! test_mat2_inverse() +{ + Matrix2 a = { 3, 5, 6, 2 }; + Matrix2 a_inv = a.inverse()!; + double sum = ((double[<4>])a_inv.mul(a).m).sum(); + assert(math::abs(sum - 2.0) < math::FLOAT_EPSILON, + "wrong inverse: sum of all elements should be 2, but got: %g", sum); +} + fn void test_vec3() { Vec3 cross = Vec3{2,3,4}.cross(Vec3{5,6,7}); assert(cross == Vec3{-3,6,-3}); -} \ No newline at end of file +}