GY-63_MS5611/libraries/Complex/complex.h

116 lines
2.6 KiB
C
Raw Normal View History

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