From ee14ad272e68d9363202d7f668e0b20302827209 Mon Sep 17 00:00:00 2001 From: hachem Date: Mon, 14 Sep 2026 12:20:52 +0200 Subject: feat: simd + testing + formatting --- src/maths/complex.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'src/maths/complex.c') diff --git a/src/maths/complex.c b/src/maths/complex.c index 3115fdd..44e255f 100644 --- a/src/maths/complex.c +++ b/src/maths/complex.c @@ -4,8 +4,7 @@ struct PsiComplex psi_new_complex(double real, double imaginary) { - return (struct PsiComplex) - { + return (struct PsiComplex){ real, imaginary, }; @@ -13,8 +12,7 @@ struct PsiComplex psi_new_complex(double real, double imaginary) struct PsiComplex psi_new_complex_from_real(double real) { - return (struct PsiComplex) - { + return (struct PsiComplex){ real, 0.0, }; @@ -22,8 +20,7 @@ struct PsiComplex psi_new_complex_from_real(double real) struct PsiComplex psi_conjugate_complex(struct PsiComplex z) { - return (struct PsiComplex) - { + return (struct PsiComplex){ z.real, -z.imaginary, }; @@ -31,8 +28,7 @@ struct PsiComplex psi_conjugate_complex(struct PsiComplex z) struct PsiComplex psi_neg_complex(struct PsiComplex z) { - return (struct PsiComplex) - { + return (struct PsiComplex){ -z.real, -z.imaginary, }; @@ -59,8 +55,7 @@ struct PsiComplex psi_sqrt_complex(struct PsiComplex z) double half_theta = psi_phase_complex(z) / 2.0; double sqrt_r = sqrt(r); - return (struct PsiComplex) - { + return (struct PsiComplex){ sqrt_r * cos(half_theta), sqrt_r * sin(half_theta), }; @@ -68,8 +63,7 @@ struct PsiComplex psi_sqrt_complex(struct PsiComplex z) struct PsiComplex psi_add_complex(struct PsiComplex a, struct PsiComplex b) { - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real + b.real, a.imaginary + b.imaginary, }; @@ -77,8 +71,7 @@ struct PsiComplex psi_add_complex(struct PsiComplex a, struct PsiComplex b) struct PsiComplex psi_sub_complex(struct PsiComplex a, struct PsiComplex b) { - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real - b.real, a.imaginary - b.imaginary, }; @@ -87,8 +80,7 @@ struct PsiComplex psi_sub_complex(struct PsiComplex a, struct PsiComplex b) struct PsiComplex psi_mul_complex(struct PsiComplex a, struct PsiComplex b) { // (a + bi)(c + di) = (ac - bd) + (ad + bc)i - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real * b.real - a.imaginary * b.imaginary, a.real * b.imaginary + a.imaginary * b.real, }; @@ -98,8 +90,7 @@ struct PsiComplex psi_div_complex(struct PsiComplex a, struct PsiComplex b) { // (a + bi) / (c + di) = ((ac + bd) + (bc - ad)i) / (c² + d²) double denom = b.real * b.real + b.imaginary * b.imaginary; - return (struct PsiComplex) - { + return (struct PsiComplex){ (a.real * b.real + a.imaginary * b.imaginary) / denom, (a.imaginary * b.real - a.real * b.imaginary) / denom, }; @@ -107,8 +98,7 @@ struct PsiComplex psi_div_complex(struct PsiComplex a, struct PsiComplex b) struct PsiComplex psi_add_complex_real(struct PsiComplex a, double b) { - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real + b, a.imaginary, }; @@ -116,8 +106,7 @@ struct PsiComplex psi_add_complex_real(struct PsiComplex a, double b) struct PsiComplex psi_sub_complex_real(struct PsiComplex a, double b) { - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real - b, a.imaginary, }; @@ -125,8 +114,7 @@ struct PsiComplex psi_sub_complex_real(struct PsiComplex a, double b) struct PsiComplex psi_mul_complex_real(struct PsiComplex a, double b) { - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real * b, a.imaginary * b, }; @@ -134,8 +122,7 @@ struct PsiComplex psi_mul_complex_real(struct PsiComplex a, double b) struct PsiComplex psi_div_complex_real(struct PsiComplex a, double b) { - return (struct PsiComplex) - { + return (struct PsiComplex){ a.real / b, a.imaginary / b, }; -- cgit v1.3