Include : Header per EgtNumKernel (DllMain, Complex, PolynomialZeros).
This commit is contained in:
+340
@@ -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 <math.h>
|
||||
#include <float.h>
|
||||
|
||||
|
||||
//---------------------------- 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 ;
|
||||
}
|
||||
@@ -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) ;
|
||||
@@ -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) ;
|
||||
Reference in New Issue
Block a user