mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added easings. Move of math to own folder.
This commit is contained in:
committed by
Christoffer Lerno
parent
92507ee388
commit
e09628b664
31
lib/std/math/math.complex.c3
Normal file
31
lib/std/math/math.complex.c3
Normal file
@@ -0,0 +1,31 @@
|
||||
module std::math::complex<Type>;
|
||||
|
||||
union Complex
|
||||
{
|
||||
struct
|
||||
{
|
||||
Type r, c;
|
||||
}
|
||||
Type[<2>] v;
|
||||
}
|
||||
|
||||
macro Complex Complex.add(Complex a, Complex b)
|
||||
{
|
||||
return Complex { .v = a.v + b.v };
|
||||
}
|
||||
|
||||
macro Complex Complex.sub(Complex a, Complex b)
|
||||
{
|
||||
return Complex { .v = a.v - b.v };
|
||||
}
|
||||
|
||||
macro Complex Complex.mult(Complex a, Complex b)
|
||||
{
|
||||
return Complex { .r = a.r * b.r - a.c * b.c, .c = a.r * b.c + b.r * a.c };
|
||||
}
|
||||
|
||||
fn Complex Complex.div(Complex a, Complex b)
|
||||
{
|
||||
Type div = b.r * b.r + b.c * b.c;
|
||||
return Complex { .r = (a.r * b.r + a.c * b.c) / div, .c = (a.c * b.r - a.r * b.c) / div };
|
||||
}
|
||||
Reference in New Issue
Block a user