117 lines
2.3 KiB
C
Raw Normal View History

2020-11-27 11:10:47 +01:00
#pragma once
2013-09-29 14:16:03 +02:00
//
2013-09-29 14:13:36 +02:00
// FILE: Complex.h
// AUTHOR: Rob Tillaart
2021-10-19 19:44:42 +02:00
// VERSION: 0.2.4
2020-11-27 11:10:47 +01:00
// PURPOSE: Arduino library for Complex math
// URL: https://github.com/RobTillaart/Complex
// http://arduino.cc/playground/Main/ComplexMath
2013-09-29 14:16:03 +02:00
//
2013-09-29 14:13:36 +02:00
2021-09-14 11:58:53 +02:00
2013-09-29 14:13:36 +02:00
#include "Arduino.h"
#include "Printable.h"
2021-09-14 11:58:53 +02:00
2021-10-19 19:44:42 +02:00
#define COMPLEX_LIB_VERSION (F("0.2.4"))
2021-09-14 11:58:53 +02:00
class Complex: public Printable
2013-09-29 14:13:36 +02:00
{
public:
2020-11-27 11:10:47 +01:00
Complex(const float r = 0, const float i = 0) : re(r), im(i) {};
2021-09-14 11:58:53 +02:00
Complex(const Complex &c) : re(c.re), im(c.im) {};
2013-09-29 14:16:03 +02:00
2018-04-02 20:48:12 +02:00
void set(const float r, const float i ) { re = r; im = i; };
2021-01-29 12:31:58 +01:00
void setReal(const float r) { re = r; };
void setImag(const float i ) { im = i; };
2018-04-02 20:48:12 +02:00
float real() { return re; };
float imag() { return im; };
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
size_t printTo(Print& p) const;
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
2021-01-29 12:31:58 +01:00
void polar(const float modulus, const float phase);
float phase() { return atan2(im, re); };
float modulus() { return hypot(re, im); };
// conjugate is the number mirrored in x-axis
2021-01-29 12:31:58 +01:00
Complex conjugate() { return Complex(re, -im); };
Complex reciprocal();
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
bool operator == (const Complex&);
bool operator != (const Complex&);
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
2013-09-29 14:16:03 +02:00
Complex operator - (); // negation
2021-09-14 11:58:53 +02:00
Complex operator + (const Complex&);
Complex operator - (const Complex&);
Complex operator * (const Complex&);
Complex operator / (const Complex&);
2013-09-29 14:13:36 +02:00
Complex& operator += (const Complex&);
Complex& operator -= (const Complex&);
Complex& operator *= (const Complex&);
Complex& operator /= (const Complex&);
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
Complex c_sqrt();
Complex c_sqr();
Complex c_exp();
Complex c_log();
Complex c_log10();
2015-03-06 14:02:38 +01:00
Complex c_pow(const Complex &);
Complex c_logn(const Complex &);
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
Complex c_sin();
Complex c_cos();
Complex c_tan();
Complex c_asin();
Complex c_acos();
Complex c_atan();
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
Complex c_csc();
Complex c_sec();
Complex c_cot();
Complex c_acsc();
Complex c_asec();
Complex c_acot();
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
Complex c_sinh();
Complex c_cosh();
Complex c_tanh();
Complex c_asinh();
Complex c_acosh();
Complex c_atanh();
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
Complex c_csch();
Complex c_sech();
Complex c_coth();
Complex c_acsch();
Complex c_asech();
Complex c_acoth();
2013-09-29 14:16:03 +02:00
2021-09-14 11:58:53 +02:00
protected:
2018-04-02 20:48:12 +02:00
float re;
float im;
Complex gonioHelper1(const byte);
Complex gonioHelper2(const byte);
2013-09-29 14:13:36 +02:00
};
2021-10-19 19:44:42 +02:00
static Complex one(1, 0);
2021-10-19 19:44:42 +02:00
2020-11-27 11:10:47 +01:00
// -- END OF FILE --
2021-10-19 19:44:42 +02:00