mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope. Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
25 lines
788 B
Plaintext
25 lines
788 B
Plaintext
module std::math::complex(<Real>);
|
|
|
|
union Complex
|
|
{
|
|
struct
|
|
{
|
|
Real r, c;
|
|
}
|
|
Real[<2>] v;
|
|
}
|
|
|
|
|
|
const Complex IDENTITY = { 1, 0 };
|
|
macro Complex Complex.add(self, Complex b) => Complex { .v = self.v + b.v };
|
|
macro Complex Complex.add_each(self, Real b) => Complex { .v = self.v + b };
|
|
macro Complex Complex.sub(self, Complex b) => Complex { .v = self.v - b.v };
|
|
macro Complex Complex.sub_each(self, Real b) => Complex { .v = self.v - b };
|
|
macro Complex Complex.scale(self, Real s) => Complex { .v = self.v * s };
|
|
macro Complex Complex.mul(self, Complex b) => { self.r * b.r - self.c * b.c, self.r * b.c + b.r * self.c };
|
|
macro Complex Complex.div(self, Complex b)
|
|
{
|
|
Real div = b.v.dot(b.v);
|
|
return Complex{ (self.r * b.r + self.c * b.c) / div, (self.c * b.r - self.r * b.c) / div };
|
|
}
|