aboutsummaryrefslogtreecommitdiff
path: root/src/maths/complex.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-14 12:20:52 +0200
committerhachem <im@hachem.wtf>2026-09-14 12:20:52 +0200
commitee14ad272e68d9363202d7f668e0b20302827209 (patch)
tree88dd1012ad7f9d6ac7abeb7562dac2194794b823 /src/maths/complex.c
parentae07aab1442a45bbddb79e066f15eaf252a4254a (diff)
feat: simd + testing + formatting
Diffstat (limited to 'src/maths/complex.c')
-rw-r--r--src/maths/complex.c39
1 files changed, 13 insertions, 26 deletions
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,
};