Commit 1fa8f54d authored by Шагин Ренал Рустемович's avatar Шагин Ренал Рустемович
Browse files

Added complex, submodule for him, operators

parent efd66849
No related merge requests found
Showing with 87 additions and 0 deletions
+87 -0
.gitignore 0 → 100644
.vs/
out/
.DS_Store
.idea/
cmake-build-debug/
cmake-build-release/
build/
\ No newline at end of file
.gitmodules 0 → 100644
[submodule "labb"]
path = labb
url = https://git.miem.hse.ru/lalalalaba/labb.git
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)
Subproject commit 598d2ec8b07b910384b538b70802aa8f2f95edb9
#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;
}
#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(); }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment