From 47c83be5df7e2ee539da9bc55f6431057ba9323e Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Wed, 8 Jan 2014 14:41:20 +0000 Subject: [PATCH] Include : Header per EgtNumKernel (DllMain, Complex, PolynomialZeros). --- ENkComplex.h | 340 +++++++++++++++++++++++++++++++++++++++++++ ENkDllMain.h | 31 ++++ ENkPolynomialZeros.h | 44 ++++++ 3 files changed, 415 insertions(+) create mode 100644 ENkComplex.h create mode 100644 ENkDllMain.h create mode 100644 ENkPolynomialZeros.h diff --git a/ENkComplex.h b/ENkComplex.h new file mode 100644 index 0000000..e92526c --- /dev/null +++ b/ENkComplex.h @@ -0,0 +1,340 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : ENkComplex.h Data : 08.01.14 Versione : 1.5a1 +// Contenuto : Dichiarazione classe dei numeri complessi. +// +// +// +// Modifiche : 08.01.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +//---------------------------Include------------------------------------------ +#include +#include + + +//---------------------------- Class Complex --------------------------------- +class Complex +{ + public : + Complex( double x, double y) : re( x), im( x) {} + Complex( double x) : re( x), im( 0) {} + Complex( void) : re( 0), im( 0) {} + void Set( double x, double y) { re = x ; im = y ; } + + public : + Complex operator +=( double dVal) ; + Complex operator +=( Complex& cVal) ; + Complex operator -=( double dVal) ; + Complex operator -=( Complex& cVal) ; + Complex operator *=( double dVal) ; + Complex operator *=( Complex& cVal) ; + Complex operator /=( double dVal) ; + Complex operator /=( Complex& cVal) ; + Complex operator >>=( int n) ; + Complex operator <<=( int n) ; + + public : + double re ; + double im ; +} ; + +//------------------------------ Functions ----------------------------------- +Complex sqrt( Complex& cVal) ; +Complex log( Complex& cVal) ; +Complex exp( Complex & cVal) ; +Complex cosh( Complex& cVal) ; +Complex sinh( Complex& cVal) ; +Complex tanh( Complex& cVal) ; +Complex cos( Complex& cVal) ; +Complex isin( Complex& cVal) ; +Complex sin( Complex& cVal) ; +Complex itan( Complex& cVal) ; +Complex tan( Complex& cVal) ; +Complex acosh( Complex& cVal) ; +Complex asinh( Complex& cVal) ; +Complex atanh( Complex& cVal) ; +Complex acos( Complex& cVal) ; +Complex asin( Complex& cVal) ; +Complex atan( Complex& cVal) ; + + +//------------------------------ Functions inline ----------------------------------- +// !z and !!z to use as boolean +inline int +operator !( Complex& cVal) +{ + return ( ( cVal.re || cVal.im) ? 0 : 1) ; +} + +//---------------------------------------------------------------------------- +// ~z = z +inline Complex +operator ~( Complex& cVal) +{ + Complex cRes ; + + + cRes.re = cVal.re ; + cRes.im = - cVal.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline double +Re( Complex& cVal) +{ + return cVal.re ; +} + +//---------------------------------------------------------------------------- +inline double +Im( Complex& cVal) +{ + return cVal.im ; +} + +//---------------------------------------------------------------------------- +// negation +inline Complex +operator -( Complex& cVal) +{ + Complex cRes ; + + + cRes.re = - cVal.re ; + cRes.im = - cVal.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator -( Complex& cVal1, Complex& cVal2) +{ + Complex cRes ; + + + cRes.re = cVal1.re - cVal2.re ; + cRes.im = cVal1.im - cVal2.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator -( double dVal1, Complex& cVal2) +{ + Complex cRes ; + + + cRes.re = dVal1 - cVal2.re ; + cRes.im = - cVal2.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator -( Complex& cVal1, double dVal2) +{ + Complex cRes ; + + + cRes.re = cVal1.re - dVal2 ; + cRes.im = cVal1.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +// addition +inline Complex +operator +( Complex& cVal) +{ + return cVal ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator +( double dVal1, Complex& cVal2) +{ + Complex cRes ; + + + cRes.re = dVal1 + cVal2.re ; + cRes.im = cVal2.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator +( Complex& cVal1, double dVal2) +{ + Complex cRes ; + + + cRes.re = cVal1.re + dVal2 ; + cRes.im = cVal1.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator +( Complex& cVal1, Complex& cVal2) +{ + Complex cRes ; + + + cRes.re = cVal1.re + cVal2.re ; + cRes.im = cVal1.im + cVal2.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +// multiplication +inline Complex +operator *( Complex& cVal1, Complex& cVal2) +{ + Complex cRes ; + + + cRes.re = cVal1.re * cVal2.re - cVal1.im * cVal2.im ; + cRes.im = cVal1.re * cVal2.im + cVal1.im * cVal2.re ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator *( double dVal1, Complex& cVal2) +{ + Complex cRes ; + + + cRes.re = dVal1 * cVal2.re ; + cRes.im = dVal1 * cVal2.im ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator *( Complex& cVal1, double dVal2) +{ + Complex cRes ; + + + cRes.re = cVal1.re * dVal2 ; + cRes.im = cVal1.im * dVal2 ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +// 2 +// m2(z) = |z|...(used by / ) +inline double +m2( Complex& cVal) +{ + return ( cVal.re * cVal.re + cVal.im * cVal.im) ; +} + +//---------------------------------------------------------------------------- +// mod(z) = |z|.............. +inline double +mod( Complex& cVal) +{ + if ( fabs( cVal.im) < DBL_EPSILON) + return fabs( cVal.re) ; + if ( fabs( cVal.re) < DBL_EPSILON) + return fabs( cVal.im) ; + + return sqrt( m2( cVal)) ; +} + +//---------------------------------------------------------------------------- +inline Complex +operator /( Complex& cVal1, double dVal2) +{ + double dInv ; + Complex cRes ; + + + dInv = 1.0 / dVal2 ; + cRes.re = cVal1.re * dInv ; + cRes.im = cVal1.im * dInv ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +// inversion +inline Complex +inv( Complex& cVal) +{ + return ( ~ cVal / m2( cVal)) ; +} + +//---------------------------------------------------------------------------- +// division as mult for inv +inline Complex +operator /( Complex& cVal1, Complex& cVal2) +{ + + if ( fabs( cVal2.im) < DBL_EPSILON) + return ( cVal1 / cVal2.re) ; + + return ( cVal1 * inv( cVal2)) ; +} + +//---------------------------------------------------------------------------- +// fast multiply by +i +inline Complex +itimes( Complex& cVal) +{ + Complex cRes ; + + + cRes.re = - cVal.im ; + cRes.im = cVal.re ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +// right shift............. +inline Complex +operator >>( Complex& cVal, int n) +{ + Complex cRes ; + + + cRes.re = ldexp( cVal.re, -n) ; + cRes.im = ldexp( cVal.im, -n) ; + + return cRes ; +} + +//---------------------------------------------------------------------------- +// left shift.............. +inline Complex +operator <<( Complex& cVal, int n) +{ + Complex cRes ; + + + cRes.re = ldexp( cVal.re, +n) ; + cRes.im = ldexp( cVal.im, +n) ; + + return cRes ; +} diff --git a/ENkDllMain.h b/ENkDllMain.h new file mode 100644 index 0000000..2a3c676 --- /dev/null +++ b/ENkDllMain.h @@ -0,0 +1,31 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : ENkDllMain.h Data : 08.01.14 Versione : 1.5a1 +// Contenuto : Prototipi funzioni generali della DLL. +// +// +// +// Modifiche : 08.01.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +class ILogger ; + +//----------------------- Macro per import/export ---------------------------- +#undef ENK_EXPORT +#if defined( I_AM_ENK) // da definirsi solo nella DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//----------------------------------------------------------------------------- +// restituisce la versione della Dll (stringa del tipo 1.4a5) +EGK_EXPORT const char* GetENkVersion( void) ; +// permette di impostare il logger per la Dll +EGK_EXPORT void SetENkLogger( ILogger* pLogger) ; diff --git a/ENkPolynomialZeros.h b/ENkPolynomialZeros.h new file mode 100644 index 0000000..0e81fc2 --- /dev/null +++ b/ENkPolynomialZeros.h @@ -0,0 +1,44 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : ENkPolynomialZeros.h Data : 08.01.14 Versione : 1.5a1 +// Contenuto : Dichiarazione di funzioni per il calcolo degli zeri di polinomi. +// +// +// +// Modifiche : 08.01.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +//----------------------- Macro per import/export ---------------------------- +#undef ENK_EXPORT +#if defined( I_AM_ENK) // da definirsi solo nella DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//---------------------------Include------------------------------------------ +#include "\EgtDev\Include\ENkComplex.h" + + +//---------------------------------------------------------------------------- +// Calcola gli zeri di un polinomio a coefficienti reali +// nDegree = grado +// adPoly = array (dimensioni nDegree + 1) dei coefficienti (dal grado pił basso al pił alto) +// adRoot = array degli zeri +// pnIter = numero di iterazioni +// valore di ritorno = numero di zeri trovati +EGK_EXPORT int PolynomialZeros( int nDegree, double adPoly[], double adRoot[], int* pnIter = NULL) ; + +//---------------------------------------------------------------------------- +// Calcola gli zeri di un polinomio a coefficienti complessi +// nDegree = grado +// acPoly = array (dimensioni nDegree + 1) dei coefficienti (dal grado pił basso al pił alto) +// acRoot = array degli zeri +// pnIter = numero di iterazioni +// valore di ritorno = numero di zeri trovati +EGK_EXPORT int PolynomialZeros( int nDegree, Complex acPoly[], Complex acRoot[], int* pnIter = NULL) ;