+ version 0.1.08

+ refactor
This commit is contained in:
rob tillaart 2015-03-06 14:02:38 +01:00
parent 39de4fa177
commit 411126e5a9
2 changed files with 23 additions and 20 deletions

View File

@ -1,13 +1,14 @@
//
// FILE: Complex.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// VERSION: 0.1.08
// PURPOSE: library for Complex math for Arduino
// URL: http://arduino.cc/playground/Main/ComplexMath
//
// Released to the public domain
//
// 0.1.08 - refactor
// 0.1.07 - refactor interfaces
#include "complex.h"
@ -75,10 +76,10 @@ Complex Complex::operator * (const Complex &c)
Complex Complex::operator / (const Complex &c)
{
double f = (c.re*c.re + c.im*c.im);
double r = re * c.re + im * c.im;
double i = im * c.re - re * c.im;
return Complex(r / f, i / f);
double f = 1.0/(c.re*c.re + c.im*c.im);
double r = (re * c.re + im * c.im) * f;
double i = (im * c.re - re * c.im) * f;
return Complex(r, i);
}
Complex& Complex::operator += (const Complex &c)
@ -107,10 +108,10 @@ Complex& Complex::operator *= (const Complex &c)
Complex& Complex::operator /= (const Complex &c)
{
double f = 1.0/(c.re*c.re + c.im*c.im);
double r = re * c.re + im * c.im;
double i = re * c.im - im * c.re;
re = r*f;
im = -i*f;
double r = (re * c.re + im * c.im) * f;
double i = (im * c.re - re * c.im) * f;
re = r;
im = i;
return *this;
}
@ -148,15 +149,17 @@ Complex Complex::c_log()
return Complex(log(m), p);
}
Complex Complex::c_pow(Complex c)
Complex Complex::c_pow(const Complex &c)
{
Complex t = c * c_log();
Complex t = c_log();
t = t * c;
return t.c_exp();
}
Complex Complex::c_logn(Complex c)
Complex Complex::c_logn(const Complex &c)
{
return c_log()/c.c_log();
Complex t = c;
return c_log()/t.c_log();
}
Complex Complex::c_log10()

View File

@ -1,7 +1,7 @@
//
// FILE: Complex.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// VERSION: 0.1.08
// PURPOSE: library for Complex math for Arduino
// URL: http://arduino.cc/playground/Main/ComplexMath
//
@ -19,7 +19,7 @@
#include "Printable.h"
#define COMPLEX_LIB_VERSION "0.1.07"
#define COMPLEX_LIB_VERSION "0.1.08"
// five categories of functions can be switched per category
// by (un)commenting next lines.
@ -71,8 +71,8 @@ public:
Complex c_exp();
Complex c_log();
Complex c_log10();
Complex c_pow(Complex);
Complex c_logn(Complex);
Complex c_pow(const Complex &);
Complex c_logn(const Complex &);
#endif
#ifdef COMPLEX_GONIO_1