21 const T EPSILON = 64 * (std::numeric_limits<T>::epsilon());
23 T numNorm = (T)
std::sqrt(
double(numReal)*numReal + double(numIm)*numIm);
25 if (numNorm <= EPSILON)
27 resReal = resIm = T(0);
33 T resNorm = (T) std::pow(numNorm, ex);
41 angle = (-
M_PI - 2.0*std::atan(numIm / (numNorm - numReal)))*ex;
45 angle = (
M_PI - 2.0*std::atan(numIm / (numNorm - numReal)))*ex;
50 angle = 2.0*std::atan(numIm / (numNorm + numReal))*ex;
53 resReal = T(std::cos(angle)*resNorm);
54 resIm = T(std::sin(angle)*resNorm);
74 void eigen3D(T A11, T A12, T A13, T A22, T A23, T A33,
75 T &ev1, T &ev2, T &ev3)
78 T A2 = -(A11+A22+A33);
79 T A1 = -(A12*A12+A13*A13+A23*A23-A11*A22-A11*A33-A22*A33);
80 T A0 = -(A11*A22*A33+2*A12*A13*A23-A12*A12*A33-A11*A23*A23-A13*A13*A22);
82 T R = (9*A2*A1-27*A0-2*
cube(A2))/T(54);
91 if (
std::abs(sqrtDIm) < 128 * (std::numeric_limits<T>::epsilon()) && R < sqrtDReal )
93 sqrtDIm = 128 * (std::numeric_limits<T>::epsilon());
97 myComplexPow(R+sqrtDReal, sqrtDIm, T(1.0/3.0), SReal, SIm);
101 myComplexPow(R-sqrtDReal, -sqrtDIm, T(1.0/3.0), TReal, TIm);
103 ev1 = T(-(1.0/3.0)*A2 + (SReal+TReal));
104 ev2 = T(-(1.0/3.0)*A2 - 0.5*(SReal+TReal) - 0.5*
std::sqrt(3.0)*(SIm-TIm));
105 ev3 = T(-(1.0/3.0)*A2 - 0.5*(SReal+TReal) + 0.5*
std::sqrt(3.0)*(SIm-TIm));
void sqrt(const TImage &in, TImage &out)
void myComplexSqrt(T num, T &resReal, T &resIm)
Belongs to package Box Do not include directly, include til/Box.h instead.
void myComplexPow(T numReal, T numIm, T ex, T &resReal, T &resIm)
General macros, definitions and functions.
INLINE const T cube(const T &a)
Max of two numbers.
numeric_array< T, D > abs(const numeric_array< T, D > &a)
Absolute value, element-wise.
T angle(T x, T y, T norm)
Returns the angle between (x,y) and the x-axis, with the norm of (x,y) provided.
void eigen3D(T A11, T A12, T A13, T A22, T A23, T A33, T &ev1, T &ev2, T &ev3)
void square(const TImage &in, TImage &out)