template
stringlengths
20
4.72k
template<typename T> PFC_INLINE complex<T> rcbrt_z(const complex<T> &c_) { // component-wise cubic root typedef typename math<T>::scalar_t scalar_t; return complex<T>(c_.real?c_.real<0?-std::pow(-c_.real, scalar_t(-1.0/3.0)):std::pow(c_.real, scalar_t(-1.0/3.0)):0, c_.imag?c_.imag<0?-std::pow(-c_.imag, scalar_t(-1.0/3.0)):std::pow(c_.imag, scalar_t(-1.0/3.0)):0); }
template<typename T> PFC_INLINE typename math<T>::scalar_t norm(const complex<T> &c_) { // norm of the complex (=complex length) return std::sqrt(c_.real*c_.real+c_.imag*c_.imag); }
template<typename T> PFC_INLINE typename math<T>::scalar_t rnorm(const complex<T> &c_) { // reciprocal norm of the complex typedef typename math<T>::scalar_t scalar_t; scalar_t n2=c_.real*c_.real+c_.imag*c_.imag; PFC_ASSERT_PEDANTIC(n2); return scalar_t(1)/std::sqrt(n2); }
template<typename T> PFC_INLINE typename math<T>::scalar_t rnorm_z(const complex<T> &c_) { // reciprocal norm of the vector typedef typename math<T>::scalar_t scalar_t; scalar_t n2=c_.real*c_.real+c_.imag*c_.imag; return n2>0?scalar_t(1)/std::sqrt(n2):0; }
template<typename T> PFC_INLINE typename math<T>::scalar_t norm2(const complex<T> &c_) { // squared norm of the complex return c_.real*c_.real+c_.imag*c_.imag; }
template<typename T> PFC_INLINE typename math<T>::scalar_t rnorm2(const complex<T> &c_) { // reciprocal squared norm of the complex typedef typename math<T>::scalar_t scalar_t; scalar_t n2=c_.real*c_.real+c_.imag*c_.imag; PFC_ASSERT_PEDANTIC(n2); return scalar_t(1)/n2; }
template<typename T> PFC_INLINE typename math<T>::scalar_t rnorm2_z(const complex<T> &c_) { // reciprocal squared norm of the vector typedef typename math<T>::scalar_t scalar_t; scalar_t v=c_.real*c_.real+c_.imag*c_.imag; return v>0?scalar_t(1)/v:0; }
template<typename T> PFC_INLINE complex<T> unit(const complex<T> &c_) { // unit complex of the complex typedef typename math<T>::scalar_t scalar_t; scalar_t n2=c_.real*c_.real+c_.imag*c_.imag; PFC_ASSERT_PEDANTIC(n2); scalar_t rs=scalar_t(1)/std::sqrt(n2); return complex<T>(c_.real*rs, c_.imag*rs); }
template<typename T> PFC_INLINE complex<T> unit_z(const complex<T> &c_) { // unit complex of the complex. if |c|=0, return c=[0, 0] typedef typename math<T>::scalar_t scalar_t; scalar_t rs=c_.real*c_.real+c_.imag*c_.imag; if(!rs) return complex<T>(0, 0); rs=scalar_t(1)/std::sqrt(rs); return complex<T>(c_.real*rs, c_.imag*rs); }
template<typename T> PFC_INLINE complex<T> conj(const complex<T> &c_) { // conjugate of the complex return complex<T>(c_.real, -c_.imag); }
template<typename T> PFC_INLINE typename math<T>::scalar_t dot(const complex<T> &c0_, const complex<T> &c1_) { // dot-product of complex numbers return c0_.real*c1_.real+c0_.imag*c1_.imag; }
template<typename T> PFC_INLINE typename math<T>::scalar_t dot1(const complex<T> &c_) { // dot-product with [1, 1] return c_.real+c_.imag; }
template<typename T> PFC_INLINE typename math<T>::scalar_t arg(const complex<T> &c_) { // argument of the complex return atan2(c_.imag, c_.real); }
template<typename T> PFC_INLINE void neg(complex<T> &c_) { // negate the complex c_.real=-c_.real; c_.imag=-c_.imag; }
template<typename T, class Rng> PFC_INLINE void rand_u(complex<T> &cr_, Rng &rng_) { // random unit complex number (even distribution on unit circle) sincos(cr_.real, cr_.imag, typename math<T>::scalar_t(rng_.rand_ureal1())*math<T>::two_pi); }
template<typename T, class Rng> PFC_INLINE void rand_real1(complex<T> &cr_, Rng &rng_) { // random complex number where each component is in range [-1, 1] typedef typename math<T>::scalar_t scalar_t; cr_.real=scalar_t(rng_.rand_real1()); cr_.imag=scalar_t(rng_.rand_real1()); }
template<typename T, class Rng> PFC_INLINE void rand_ureal1(complex<T> &cr_, Rng &rng_) { // random complex number where each component is in range [0, 1] typedef typename math<T>::scalar_t scalar_t; cr_.real=scalar_t(rng_.rand_ureal1()); cr_.imag=scalar_t(rng_.rand_ureal1()); }
template<typename T> PFC_INLINE complex<T> smoothstep(const complex<T> &c_) { // component-wise smoothstep function typedef typename math<T>::scalar_t scalar_t; PFC_ASSERT_PEDANTIC(c_.real>=0 && c_.real<=scalar_t(1) && c_.imag>=0 && c_.imag<=scalar_t(1)); return complex<T>(c_.real*c_.real*(scalar_t(3)-scalar_t(2)*c_.real), c_.imag*c_.imag*(scalar_t(3)-scalar_t(2)*c_.imag)); }
template<typename T> PFC_INLINE complex<T> smootherstep(const complex<T> &c_) { // component-wise smootherstep function typedef typename math<T>::scalar_t scalar_t; PFC_ASSERT_PEDANTIC(c_.real>=0 && c_.real<=scalar_t(1) && c_.imag>=0 && c_.imag<=scalar_t(1)); return complex<T>(c_.real*c_.real*c_.real*(c_.real*(c_.real*scalar_t(6)-scalar_t(15))+scalar_t(10)), c_.imag*c_.imag*c_.imag*(c_.imag*(c_.imag*scalar_t(6)-scalar_t(15))+scalar_t(10))); }
template<typename T> PFC_INLINE complex<T> lerp(const complex<T> &c0_, const complex<T> &c1_, typename math<T>::scalar_t t_) { // linear complex interpolation. f(t=0)=c0, f(t=1)=c1 return complex<T>(c0_.real+(c1_.real-c0_.real)*t_, c0_.imag+(c1_.imag-c0_.imag)*t_); }
template<typename T> PFC_INLINE complex<T> nlerp(const complex<T> &c0_, const complex<T> &c1_, typename math<T>::scalar_t t_) { // normalized linear complex interpolation. f(t=0)=c0/|c0|, f(t=1)=c1/|c1| typedef typename math<T>::scalar_t scalar_t; complex<T> c(c0_.real+(c1_.real-c0_.real)*t_, c0_.imag+(c1_.imag-c0_.imag)*t_); scalar_t n2=c.real*c.real+c.imag*c.imag; PFC_ASSERT_PEDANTIC(n2); scalar_t rs=scalar_t(1)/std::sqrt(n2); return complex<T>(c.real*rs, c.imag*rs); }
template<typename T> PFC_INLINE complex<T> nlerp_z(const complex<T> &c0_, const complex<T> &c1_, typename math<T>::scalar_t t_) { // normalized linear complex interpolation. f(t=0)=c0/|c0|, f(t=1)=c1/|c1|. if interpolated |c|=0, return [0, 0] typedef typename math<T>::scalar_t scalar_t; complex<T> c(c0_.real+(c1_.real-c0_.real)*t_, c0_.imag+(c1_.imag-c0_.imag)*t_); scalar_t rs=c.real*c.real+c.imag*c.imag; if(!rs) return complex<T>(0, 0); rs=scalar_t(1)/std::sqrt(rs); return complex<T>(c.real*rs, c.imag*rs); }
template<typename T, typename U> PFC_INLINE complex<T> to_complex(const complex<U> &c_) { // convert between complex types typedef typename math<T>::scalar_t scalar_t; return complex<T>(scalar_t(c_.real), scalar_t(c_.imag)); }
template<unsigned shuffle_, typename T> PFC_INLINE complex<T> shuffle(const complex<T> &c_) { return priv::shuffle_complex_helper<shuffle_, T>::shuffle(c_); }