16 #ifndef INCLUDED_IMATHROOTS_H
17 #define INCLUDED_IMATHROOTS_H
26 # include <thrust/complex.h>
27 # define COMPLEX_NAMESPACE thrust
29 # define COMPLEX_NAMESPACE std
34 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
106 IMATH_CONSTEXPR14
int
115 T D = b * b - 4 * a *
c;
120 T q = -(b + (b > 0 ? 1 : -1) * s) /
T (2);
139 IMATH_CONSTEXPR14
int
142 T p = (3 * s - r *
r) / 3;
143 T q = 2 * r * r * r / 27 - r * s / 3 +
t;
146 T D = p3 * p3 * p3 + q2 * q2;
148 if (D == 0 && p3 == 0)
158 auto real_root = [] (
T a,
T x) ->
T {
160 return sign *
std::pow (sign * a,
T (1) / x);
164 T v = -p / (
T (3) * u);
166 x[0] = u + v - r / 3;
170 namespace CN = COMPLEX_NAMESPACE;
171 CN::complex<T> u =
CN::pow (-q / 2 +
CN::sqrt (CN::complex<T> (D)),
T (1) /
T (3));
172 CN::complex<T>
v = -p / (
T (3) * u);
174 const T sqrt3 =
T (1.73205080756887729352744634150587);
176 CN::complex<T> y0 (u + v);
177 CN::complex<T>
y1 (-(u + v) /
T (2) + (u - v) /
T (2) * CN::complex<T> (0, sqrt3));
178 CN::complex<T>
y2 (-(u + v) /
T (2) - (u - v) /
T (2) * CN::complex<T> (0, sqrt3));
182 x[0] = y0.real() - r / 3;
183 x[1] = y1.real() - r / 3;
188 x[0] = y0.real() - r / 3;
189 x[1] = y1.real() - r / 3;
190 x[2] = y2.real() - r / 3;
196 IMATH_CONSTEXPR14
int
209 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
211 #endif // INCLUDED_IMATHROOTS_H
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 int solveCubic(T a, T b, T c, T d, T x[3])
vfloat4 sqrt(const vfloat4 &a)
GLboolean GLboolean GLboolean GLboolean a
GLdouble GLdouble GLdouble q
ImageBuf OIIO_API pow(const ImageBuf &A, cspan< float > B, ROI roi={}, int nthreads=0)
SYS_API double copysign(double x, double y)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 int solveLinear(T a, T b, T &x)
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
GLboolean GLboolean GLboolean b
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 int solveNormalizedCubic(T r, T s, T t, T x[3])
GLdouble GLdouble GLdouble y2
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 int solveQuadratic(T a, T b, T c, T x[2])