diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..45f7727a20cc4b007498fbe630efca02992d9ac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.vs/ +out/ +.DS_Store +.idea/ +cmake-build-debug/ +cmake-build-release/ +build/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..76afd71b5dfe9aa023a7e5cbca3b1ebaf5613fdc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "labb"] + path = labb + url = https://git.miem.hse.ru/lalalalaba/labb.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7a422f2e001dfaf9b96622fb3b567a47cf59e78 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.10) + +set(CMAKE_CXX_STANDARD 17) + +project(111) + +add_executable("source/complex.cpp") + +add_subdirectory(labb) + +target_link_libraries(111 PUBLIC linalg) diff --git a/labb b/labb new file mode 160000 index 0000000000000000000000000000000000000000..598d2ec8b07b910384b538b70802aa8f2f95edb9 --- /dev/null +++ b/labb @@ -0,0 +1 @@ +Subproject commit 598d2ec8b07b910384b538b70802aa8f2f95edb9 diff --git a/source/complex.cpp b/source/complex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7de00a135a69dc09b0cc5885634de82de77be286 --- /dev/null +++ b/source/complex.cpp @@ -0,0 +1,32 @@ +#include "complex.h" +#include <sstream> +#include <iomanip> +Complex& Complex::operator+=(const Complex& other) noexcept { + m_re += other.m_re; + m_im += other.m_im; + return *this; +} +Complex operator+ (const Complex& v1, const Complex& v2) { + Complex tmp(v1); + return tmp += v2; +} +Complex& Complex::operator-=(const Complex& other) noexcept { + m_re -= other.m_re; + m_im -= other.m_im; + return *this; +} +Complex operator-(const Complex& v1, const Complex& v2) { + Complex tmp(v1); + return tmp -= v2; +} +Complex& Complex::operator*=(const Complex& other) noexcept { + double new_re = m_re * other.m_re - m_im * other.m_im; + double new_im = m_re * other.m_im + m_im * other.m_re; + m_re = new_re; + m_im = new_im; + return *this; +} +Complex operator*(const Complex& v1, const Complex& v2) { + Complex tmp(v1); + return tmp *= v2; +} diff --git a/source/complex.h b/source/complex.h new file mode 100644 index 0000000000000000000000000000000000000000..0835129614fc2282fe712b95008d18427d1c4005 --- /dev/null +++ b/source/complex.h @@ -0,0 +1,33 @@ +#pragma once +#include <ostream> + +class Complex { +public: + Complex() noexcept : m_re(0), m_im(0) {} + Complex(double re) noexcept : m_re(re), m_im(0) {} + Complex(double re, double im) noexcept : m_re(re), m_im(im) {} + Complex(Complex&& other) noexcept : m_re(std::move(other.m_re)), m_im(std::move(other.m_im)) {} + Complex(const Complex& other) noexcept : m_re(other.m_re), m_im(other.m_im) {} + Complex& operator=(const Complex& other) noexcept { m_re = other.m_re; m_im = other.m_im; return *this; } + Complex& operator+= (const Complex& other) noexcept; + Complex& operator-=(const Complex& other) noexcept; + Complex& operator*=(const Complex& other) noexcept; + Complex& operator/=(const Complex& other); + double length() const noexcept { return sqrt(pow(m_re, 2) + pow(m_im, 2)); } +public: + double m_re; + double m_im; +}; + +bool operator==(const Complex& v1, const Complex& v2); +bool operator>(const Complex& v1, const Complex& v2); +bool operator<=(const Complex& v1, const Complex& v2); +Complex operator+(const Complex& v1, const Complex& v2); +Complex operator-(const Complex& v1, const Complex& v2); +Complex operator*(const Complex& v1, const Complex& v2); +Complex operator/(const Complex& v1, const Complex& v2); +std::ostream& operator<<(std::ostream& out, const Complex& v); +std::istream& operator>>(std::istream& in, Complex& v); + +bool check_char(std::istream& in, char expected); +double fabs(const Complex& value) { return value.length(); }