Skip to content

Instantly share code, notes, and snippets.

@lrobidou
Created June 19, 2025 11:03
Show Gist options
  • Save lrobidou/309bfed97825d77eadb9449e4ee0c771 to your computer and use it in GitHub Desktop.
Save lrobidou/309bfed97825d77eadb9449e4ee0c771 to your computer and use it in GitHub Desktop.
Course material : simple implementation of complex numbers in C++
#include "complex.hpp"
Complex::Complex(int32_t r, int32_t i) : _r(r), _i(i) {}
int32_t Complex::r() const { return this->_r; }
int32_t Complex::i() const { return this->_i; }
void Complex::r(int32_t r) { this->_r = r; }
void Complex::i(int32_t i) { this->_i = i; }
Complex Complex::conjugate() const { return Complex(this->_r, -this->_i); }
#ifndef STUPID_COMPLEX_H
#define STUPID_COMPLEX_H
#include <cstdint>
class Complex {
private:
int32_t _r;
int32_t _i;
public:
// constructor
Complex(int32_t r, int32_t i);
// getters
int32_t r() const;
int32_t i() const;
// setters
void r(int32_t r);
void i(int32_t i);
// methods
Complex conjugate() const;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment