54 F77_FUNC (
zbesj, ZBESJ) (
const double&,
const double&,
const double&,
56 double*,
double*, octave_idx_type&,
60 F77_FUNC (
zbesy, ZBESY) (
const double&,
const double&,
const double&,
61 const octave_idx_type&,
const octave_idx_type&,
62 double*,
double*, octave_idx_type&,
double*,
63 double*, octave_idx_type&);
66 F77_FUNC (
zbesi, ZBESI) (
const double&,
const double&,
const double&,
67 const octave_idx_type&,
const octave_idx_type&,
68 double*,
double*, octave_idx_type&,
72 F77_FUNC (
zbesk, ZBESK) (
const double&,
const double&,
const double&,
73 const octave_idx_type&,
const octave_idx_type&,
74 double*,
double*, octave_idx_type&,
78 F77_FUNC (
zbesh, ZBESH) (
const double&,
const double&,
const double&,
79 const octave_idx_type&,
const octave_idx_type&,
80 const octave_idx_type&,
double*,
double*,
81 octave_idx_type&, octave_idx_type&);
85 const octave_idx_type&,
const octave_idx_type&,
86 FloatComplex*, octave_idx_type&, octave_idx_type&);
90 const octave_idx_type&,
const octave_idx_type&,
91 FloatComplex*, octave_idx_type&,
92 FloatComplex*, octave_idx_type&);
96 const octave_idx_type&,
const octave_idx_type&,
97 FloatComplex*, octave_idx_type&, octave_idx_type&);
101 const octave_idx_type&,
const octave_idx_type&,
102 FloatComplex*, octave_idx_type&, octave_idx_type&);
106 const octave_idx_type&,
const octave_idx_type&,
107 const octave_idx_type&, FloatComplex*,
108 octave_idx_type&, octave_idx_type&);
112 const octave_idx_type&,
const octave_idx_type&,
113 double&,
double&, octave_idx_type&,
117 F77_FUNC (
cairy, CAIRY) (
const float&,
const float&,
const octave_idx_type&,
118 const octave_idx_type&,
float&,
float&,
119 octave_idx_type&, octave_idx_type&);
123 const octave_idx_type&,
const octave_idx_type&,
124 double&,
double&, octave_idx_type&);
127 F77_FUNC (
cbiry, CBIRY) (
const float&,
const float&,
const octave_idx_type&,
128 const octave_idx_type&,
float&,
float&,
163 const double&,
double&);
167 const float&,
float&);
188 #if !defined (HAVE_ACOSH)
198 #if !defined (HAVE_ACOSHF)
208 #if !defined (HAVE_ASINH)
218 #if !defined (HAVE_ASINHF)
228 #if !defined (HAVE_ATANH)
238 #if !defined (HAVE_ATANHF)
248 #if !defined (HAVE_ERF)
258 #if !defined (HAVE_ERFF)
268 #if !defined (HAVE_ERFC)
278 #if !defined (HAVE_ERFCF)
373 else if (x == 0 ||
xisinf (x))
377 #if defined (HAVE_TGAMMA)
392 #if defined (HAVE_LGAMMA)
414 #if defined (HAVE_LGAMMA_R)
416 result = lgamma_r (x, &sgngam);
430 return result +
Complex (0., M_PI);
444 else if (x == 0 ||
xisinf (x))
448 #if defined (HAVE_TGAMMA)
449 result = tgammaf (x);
463 #if defined (HAVE_LGAMMAF)
485 #if defined (HAVE_LGAMMAF_R)
487 result = lgammaf_r (x, &sgngam);
506 #if !defined (HAVE_EXPM1)
512 double ax = fabs (x);
521 for (
int i = 2; i < 7; i++)
527 for (
int i = 0; i < 4; i++)
533 retval = (x > 0) ? s : -s / (1+s);
536 retval = exp (x) - 1;
549 double im = x.imag ();
550 double u =
expm1 (x.real ());
551 double v = sin (im/2);
553 retval =
Complex (u*v + u + v, (u+1) * sin (im));
556 retval = std::exp (x) -
Complex (1);
561 #if !defined (HAVE_EXPM1F)
576 for (
int i = 2; i < 7; i++)
582 for (
int i = 0; i < 4; i++)
588 retval = (x > 0) ? s : -s / (1+s);
591 retval = exp (x) - 1;
604 float im = x.imag ();
605 float u =
expm1 (x.real ());
606 float v = sin (im/2);
616 #if !defined (HAVE_LOG1P)
622 double ax = fabs (x);
627 double u = x / (2 +
x), t = 1, s = 0;
628 for (
int i = 2; i < 12; i += 2)
629 s += (t *= u*u) / (i+1);
631 retval = 2 * (s + 1) * u;
634 retval = log (1 + x);
645 double r = x.real (), i = x.imag ();
647 if (fabs (r) < 0.5 && fabs (i) < 0.5)
649 double u = 2*r + r*r + i*i;
654 retval = std::log (
Complex (1) + x);
659 #if !defined (HAVE_CBRT)
662 static const double one_third = 0.3333333333333333333;
668 return (x / (y*y) + y + y) / 3;
675 #if !defined (HAVE_LOG1PF)
686 float u = x / (2 +
x), t = 1, s = 0;
687 for (
int i = 2; i < 12; i += 2)
688 s += (t *= u*u) / (i+1);
690 retval = 2 * (s + 1) * u;
693 retval = log (1 + x);
704 float r = x.real (), i = x.imag ();
706 if (fabs (r) < 0.5 && fabs (i) < 0.5)
708 float u = 2*r + r*r + i*i;
718 #if !defined (HAVE_CBRTF)
721 static const float one_third = 0.3333333333333333333f;
727 return (x / (y*y) + y + y) / 3;
782 return x ==
static_cast<double> (
static_cast<long> (
x));
797 double zr = z.real ();
798 double zi = z.imag ();
809 if (zi == 0.0 && zr >= 0.0)
819 if ((static_cast <long> (alpha)) & 1)
827 Complex tmp = cos (M_PI * alpha) *
zbesj (z, alpha, kode, ierr);
829 if (ierr == 0 || ierr == 3)
831 tmp -= sin (M_PI * alpha) *
zbesy (z, alpha, kode, ierr);
856 double zr = z.real ();
857 double zi = z.imag ();
861 if (zr == 0.0 && zi == 0.0)
878 if (zi == 0.0 && zr >= 0.0)
889 if ((static_cast <long> (alpha - 0.5)) & 1)
897 Complex tmp = cos (M_PI * alpha) *
zbesy (z, alpha, kode, ierr);
899 if (ierr == 0 || ierr == 3)
901 tmp += sin (M_PI * alpha) *
zbesj (z, alpha, kode, ierr);
924 double zr = z.real ();
925 double zi = z.imag ();
936 if (zi == 0.0 && zr >= 0.0)
954 if (ierr == 0 || ierr == 3)
956 Complex tmp2 = (2.0 / M_PI) * sin (M_PI * alpha)
957 *
zbesk (z, alpha, kode, ierr);
962 tmp2 *= exp (-z -
std::abs (z.real ()));
988 double zr = z.real ();
989 double zi = z.imag ();
993 if (zr == 0.0 && zi == 0.0)
1006 double rexpz =
real (expz);
1007 double iexpz =
imag (expz);
1009 double tmp = yr*rexpz - yi*iexpz;
1011 yi = yr*iexpz + yi*rexpz;
1015 if (zi == 0.0 && zr >= 0.0)
1043 double zr = z.real ();
1044 double zi = z.imag ();
1046 F77_FUNC (
zbesh, ZBESH) (zr, zi, alpha, 2, 1, 1, &yr, &yi, nz,
ierr);
1052 double rexpz =
real (expz);
1053 double iexpz =
imag (expz);
1055 double tmp = yr*rexpz - yi*iexpz;
1057 yi = yr*iexpz + yi*rexpz;
1069 Complex tmp = exp (M_PI * alpha * eye) *
zbesh1 (z, alpha, kode, ierr);
1089 double zr = z.real ();
1090 double zi = z.imag ();
1092 F77_FUNC (
zbesh, ZBESH) (zr, zi, alpha, 2, 2, 1, &yr, &yi, nz,
ierr);
1098 double rexpz =
real (expz);
1099 double iexpz =
imag (expz);
1101 double tmp = yr*rexpz - yi*iexpz;
1103 yi = yr*iexpz + yi*rexpz;
1115 Complex tmp = exp (-M_PI * alpha * eye) *
zbesh2 (z, alpha, kode, ierr);
1125 static inline Complex
1131 retval =
f (x, alpha, (scaled ? 2 : 1), ierr);
1149 retval(i,j) =
f (
x(i,j), alpha, (scaled ? 2 : 1),
ierr(i,j));
1167 retval(i,j) =
f (x, alpha(i,j), (scaled ? 2 : 1),
ierr(i,j));
1184 if (x_nr == alpha_nr && x_nc == alpha_nc)
1195 retval(i,j) =
f (
x(i,j), alpha(i,j), (scaled ? 2 : 1),
ierr(i,j));
1199 (
"%s: the sizes of alpha and x must conform", fn);
1215 retval(i) =
f (
x(i), alpha, (scaled ? 2 : 1),
ierr(i));
1231 retval(i) =
f (x, alpha(i), (scaled ? 2 : 1),
ierr(i));
1243 if (dv == alpha.
dims ())
1251 retval(i) =
f (
x(i), alpha(i), (scaled ? 2 : 1),
ierr(i));
1255 (
"%s: the sizes of alpha and x must conform", fn);
1274 retval(i,j) =
f (
x(i), alpha(j), (scaled ? 2 : 1),
ierr(i,j));
1279 #define SS_BESSEL(name, fcn) \
1281 name (double alpha, const Complex& x, bool scaled, octave_idx_type& ierr) \
1283 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1286 #define SM_BESSEL(name, fcn) \
1288 name (double alpha, const ComplexMatrix& x, bool scaled, \
1289 Array<octave_idx_type>& ierr) \
1291 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1294 #define MS_BESSEL(name, fcn) \
1296 name (const Matrix& alpha, const Complex& x, bool scaled, \
1297 Array<octave_idx_type>& ierr) \
1299 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1302 #define MM_BESSEL(name, fcn) \
1304 name (const Matrix& alpha, const ComplexMatrix& x, bool scaled, \
1305 Array<octave_idx_type>& ierr) \
1307 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1310 #define SN_BESSEL(name, fcn) \
1312 name (double alpha, const ComplexNDArray& x, bool scaled, \
1313 Array<octave_idx_type>& ierr) \
1315 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1318 #define NS_BESSEL(name, fcn) \
1320 name (const NDArray& alpha, const Complex& x, bool scaled, \
1321 Array<octave_idx_type>& ierr) \
1323 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1326 #define NN_BESSEL(name, fcn) \
1328 name (const NDArray& alpha, const ComplexNDArray& x, bool scaled, \
1329 Array<octave_idx_type>& ierr) \
1331 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1334 #define RC_BESSEL(name, fcn) \
1336 name (const RowVector& alpha, const ComplexColumnVector& x, bool scaled, \
1337 Array<octave_idx_type>& ierr) \
1339 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1342 #define ALL_BESSEL(name, fcn) \
1343 SS_BESSEL (name, fcn) \
1344 SM_BESSEL (name, fcn) \
1345 MS_BESSEL (name, fcn) \
1346 MM_BESSEL (name, fcn) \
1347 SN_BESSEL (name, fcn) \
1348 NS_BESSEL (name, fcn) \
1349 NN_BESSEL (name, fcn) \
1350 RC_BESSEL (name, fcn)
1419 return x ==
static_cast<float> (
static_cast<long> (
x));
1441 if (
imag (z) == 0.0 &&
real (z) >= 0.0)
1451 if ((static_cast <long> (alpha)) & 1)
1459 FloatComplex tmp = cosf (static_cast<float> (M_PI) * alpha)
1460 *
cbesj (z, alpha, kode, ierr);
1462 if (ierr == 0 || ierr == 3)
1464 tmp -= sinf (static_cast<float> (M_PI) * alpha)
1465 *
cbesy (z, alpha, kode, ierr);
1491 if (
real (z) == 0.0 &&
imag (z) == 0.0)
1505 if (
imag (z) == 0.0 &&
real (z) >= 0.0)
1516 if ((static_cast <long> (alpha - 0.5)) & 1)
1524 FloatComplex tmp = cosf (static_cast<float> (M_PI) * alpha)
1525 *
cbesy (z, alpha, kode, ierr);
1527 if (ierr == 0 || ierr == 3)
1529 tmp += sinf (static_cast<float> (M_PI) * alpha)
1530 *
cbesj (z, alpha, kode, ierr);
1560 if (
imag (z) == 0.0 &&
real (z) >= 0.0)
1571 if (ierr == 0 || ierr == 3)
1574 * sinf (static_cast<float> (M_PI) * alpha)
1575 *
cbesk (z, alpha, kode, ierr);
1580 tmp2 *= exp (-z -
std::abs (z.real ()));
1607 if (
real (z) == 0.0 &&
imag (z) == 0.0)
1619 float rexpz =
real (expz);
1620 float iexpz =
imag (expz);
1622 float tmp_r =
real (y) * rexpz -
imag (y) * iexpz;
1623 float tmp_i =
real (y) * iexpz +
imag (y) * rexpz;
1628 if (
imag (z) == 0.0 &&
real (z) >= 0.0)
1661 float rexpz =
real (expz);
1662 float iexpz =
imag (expz);
1664 float tmp_r =
real (y) * rexpz -
imag (y) * iexpz;
1665 float tmp_i =
real (y) * iexpz +
imag (y) * rexpz;
1678 FloatComplex tmp = exp (static_cast<float> (M_PI) * alpha * eye)
1679 *
cbesh1 (z, alpha, kode, ierr);
1704 float rexpz =
real (expz);
1705 float iexpz =
imag (expz);
1707 float tmp_r =
real (y) * rexpz -
imag (y) * iexpz;
1708 float tmp_i =
real (y) * iexpz +
imag (y) * rexpz;
1721 FloatComplex tmp = exp (-static_cast<float> (M_PI) * alpha * eye)
1722 *
cbesh2 (z, alpha, kode, ierr);
1733 static inline FloatComplex
1737 FloatComplex retval;
1739 retval =
f (x, alpha, (scaled ? 2 : 1), ierr);
1757 retval(i,j) =
f (
x(i,j), alpha, (scaled ? 2 : 1),
ierr(i,j));
1764 const FloatComplex& x,
1776 retval(i,j) =
f (x, alpha(i,j), (scaled ? 2 : 1),
ierr(i,j));
1794 if (x_nr == alpha_nr && x_nc == alpha_nc)
1805 retval(i,j) =
f (
x(i,j), alpha(i,j), (scaled ? 2 : 1),
ierr(i,j));
1809 (
"%s: the sizes of alpha and x must conform", fn);
1825 retval(i) =
f (
x(i), alpha, (scaled ? 2 : 1),
ierr(i));
1841 retval(i) =
f (x, alpha(i), (scaled ? 2 : 1),
ierr(i));
1854 if (dv == alpha.
dims ())
1862 retval(i) =
f (
x(i), alpha(i), (scaled ? 2 : 1),
ierr(i));
1866 (
"%s: the sizes of alpha and x must conform", fn);
1885 retval(i,j) =
f (
x(i), alpha(j), (scaled ? 2 : 1),
ierr(i,j));
1890 #define SS_BESSEL(name, fcn) \
1892 name (float alpha, const FloatComplex& x, bool scaled, octave_idx_type& ierr) \
1894 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1897 #define SM_BESSEL(name, fcn) \
1898 FloatComplexMatrix \
1899 name (float alpha, const FloatComplexMatrix& x, bool scaled, \
1900 Array<octave_idx_type>& ierr) \
1902 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1905 #define MS_BESSEL(name, fcn) \
1906 FloatComplexMatrix \
1907 name (const FloatMatrix& alpha, const FloatComplex& x, bool scaled, \
1908 Array<octave_idx_type>& ierr) \
1910 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1913 #define MM_BESSEL(name, fcn) \
1914 FloatComplexMatrix \
1915 name (const FloatMatrix& alpha, const FloatComplexMatrix& x, bool scaled, \
1916 Array<octave_idx_type>& ierr) \
1918 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1921 #define SN_BESSEL(name, fcn) \
1922 FloatComplexNDArray \
1923 name (float alpha, const FloatComplexNDArray& x, bool scaled, \
1924 Array<octave_idx_type>& ierr) \
1926 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1929 #define NS_BESSEL(name, fcn) \
1930 FloatComplexNDArray \
1931 name (const FloatNDArray& alpha, const FloatComplex& x, bool scaled, \
1932 Array<octave_idx_type>& ierr) \
1934 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1937 #define NN_BESSEL(name, fcn) \
1938 FloatComplexNDArray \
1939 name (const FloatNDArray& alpha, const FloatComplexNDArray& x, bool scaled, \
1940 Array<octave_idx_type>& ierr) \
1942 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1945 #define RC_BESSEL(name, fcn) \
1946 FloatComplexMatrix \
1947 name (const FloatRowVector& alpha, const FloatComplexColumnVector& x, bool scaled, \
1948 Array<octave_idx_type>& ierr) \
1950 return do_bessel (fcn, #name, alpha, x, scaled, ierr); \
1953 #define ALL_BESSEL(name, fcn) \
1954 SS_BESSEL (name, fcn) \
1955 SM_BESSEL (name, fcn) \
1956 MS_BESSEL (name, fcn) \
1957 MM_BESSEL (name, fcn) \
1958 SN_BESSEL (name, fcn) \
1959 NS_BESSEL (name, fcn) \
1960 NN_BESSEL (name, fcn) \
1961 RC_BESSEL (name, fcn)
1988 double zr = z.real ();
1989 double zi = z.imag ();
1997 Complex expz = exp (- 2.0 / 3.0 * z * sqrt (z));
1999 double rexpz =
real (expz);
2000 double iexpz =
imag (expz);
2002 double tmp = ar*rexpz - ai*iexpz;
2004 ai = ar*iexpz + ai*rexpz;
2008 if (zi == 0.0 && (! scaled || zr >= 0.0))
2020 double zr = z.real ();
2021 double zi = z.imag ();
2029 Complex expz = exp (
std::abs (
real (2.0 / 3.0 * z * sqrt (z))));
2031 double rexpz =
real (expz);
2032 double iexpz =
imag (expz);
2034 double tmp = ar*rexpz - ai*iexpz;
2036 ai = ar*iexpz + ai*rexpz;
2040 if (zi == 0.0 && (! scaled || zr >= 0.0))
2059 retval(i,j) =
airy (z(i,j), deriv, scaled,
ierr(i,j));
2077 retval(i,j) =
biry (z(i,j), deriv, scaled,
ierr(i,j));
2093 retval(i) =
airy (z(i), deriv, scaled,
ierr(i));
2109 retval(i) =
biry (z(i), deriv, scaled,
ierr(i));
2122 float zr = z.real ();
2123 float zi = z.imag ();
2131 FloatComplex expz = exp (- static_cast<float> (2.0 / 3.0) * z * sqrt (z));
2133 float rexpz =
real (expz);
2134 float iexpz =
imag (expz);
2136 float tmp = ar*rexpz - ai*iexpz;
2138 ai = ar*iexpz + ai*rexpz;
2142 if (zi == 0.0 && (! scaled || zr >= 0.0))
2154 float zr = z.real ();
2155 float zi = z.imag ();
2163 FloatComplex expz = exp (
std::abs (
real (static_cast<float> (2.0 / 3.0)
2166 float rexpz =
real (expz);
2167 float iexpz =
imag (expz);
2169 float tmp = ar*rexpz - ai*iexpz;
2171 ai = ar*iexpz + ai*rexpz;
2175 if (zi == 0.0 && (! scaled || zr >= 0.0))
2194 retval(i,j) =
airy (z(i,j), deriv, scaled,
ierr(i,j));
2212 retval(i,j) =
biry (z(i,j), deriv, scaled,
ierr(i,j));
2228 retval(i) =
airy (z(i), deriv, scaled,
ierr(i));
2244 retval(i) =
biry (z(i), deriv, scaled,
ierr(i));
2253 std::string d1_str = d1.
str ();
2254 std::string d2_str = d2.
str ();
2255 std::string d3_str = d3.
str ();
2257 (*current_liboctave_error_handler)
2258 (
"betainc: nonconformant arguments (x is %s, a is %s, b is %s)",
2259 d1_str.c_str (), d2_str.c_str (), d3_str.c_str ());
2266 std::string d1_str = d1.
str ();
2267 std::string d2_str = d2.
str ();
2268 std::string d3_str = d3.
str ();
2270 (*current_liboctave_error_handler)
2271 (
"betaincinv: nonconformant arguments (x is %s, a is %s, b is %s)",
2272 d1_str.c_str (), d2_str.c_str (), d3_str.c_str ());
2294 *pretval++ =
betainc (x, a, b(i));
2310 *pretval++ =
betainc (x, a(i), b);
2321 if (dv == b.
dims ())
2330 *pretval++ =
betainc (x, a(i), b(i));
2360 if (dv == b.
dims ())
2369 *pretval++ =
betainc (
x(i), a, b(i));
2383 if (dv == a.
dims ())
2392 *pretval++ =
betainc (
x(i), a(i), b);
2406 if (dv == a.
dims () && dv == b.
dims ())
2415 *pretval++ =
betainc (
x(i), a(i), b(i));
2442 *pretval++ =
betainc (x, a, b(i));
2458 *pretval++ =
betainc (x, a(i), b);
2469 if (dv == b.
dims ())
2478 *pretval++ =
betainc (x, a(i), b(i));
2508 if (dv == b.
dims ())
2517 *pretval++ =
betainc (
x(i), a, b(i));
2531 if (dv == a.
dims ())
2540 *pretval++ =
betainc (
x(i), a(i), b);
2554 if (dv == a.
dims () && dv == b.
dims ())
2563 *pretval++ =
betainc (
x(i), a(i), b(i));
2580 if (a < 0.0 || x < 0.0)
2582 (*current_liboctave_error_handler)
2583 (
"gammainc: A and X must be non-negative");
2607 result(i,j) =
gammainc (x, a(i,j), err);
2634 result(i,j) =
gammainc (
x(i,j), a, err);
2659 if (nr == a_nr && nc == a_nc)
2668 result(i,j) =
gammainc (
x(i,j), a(i,j), err);
2678 (
"gammainc: nonconformant arguments (arg 1 is %dx%d, arg 2 is %dx%d)",
2679 nr, nc, a_nr, a_nc);
2699 result (i) =
gammainc (x, a(i), err);
2747 if (dv == a.
dims ())
2755 result (i) =
gammainc (
x(i), a(i), err);
2765 std::string x_str = dv.
str ();
2766 std::string a_str = a.
dims ().
str ();
2768 (*current_liboctave_error_handler)
2769 (
"gammainc: nonconformant arguments (arg 1 is %s, arg 2 is %s)",
2770 x_str.c_str (), a_str. c_str ());
2785 if (a < 0.0 || x < 0.0)
2787 (*current_liboctave_error_handler)
2788 (
"gammainc: A and X must be non-negative");
2812 result(i,j) =
gammainc (x, a(i,j), err);
2839 result(i,j) =
gammainc (
x(i,j), a, err);
2864 if (nr == a_nr && nc == a_nc)
2873 result(i,j) =
gammainc (
x(i,j), a(i,j), err);
2883 (
"gammainc: nonconformant arguments (arg 1 is %dx%d, arg 2 is %dx%d)",
2884 nr, nc, a_nr, a_nc);
2904 result (i) =
gammainc (x, a(i), err);
2952 if (dv == a.
dims ())
2960 result (i) =
gammainc (
x(i), a(i), err);
2970 std::string x_str = dv.
str ();
2971 std::string a_str = a.
dims ().
str ();
2973 (*current_liboctave_error_handler)
2974 (
"gammainc: nonconformant arguments (arg 1 is %s, arg 2 is %s)",
2975 x_str.c_str (), a_str.c_str ());
2986 const double pi = 3.14159265358979323846;
2992 const float pi = 3.14159265358979323846f;
3007 static const double a[] =
3009 -2.806989788730439e+01, 1.562324844726888e+02,
3010 -1.951109208597547e+02, 9.783370457507161e+01,
3011 -2.168328665628878e+01, 1.772453852905383e+00
3013 static const double b[] =
3015 -5.447609879822406e+01, 1.615858368580409e+02,
3016 -1.556989798598866e+02, 6.680131188771972e+01,
3017 -1.328068155288572e+01
3019 static const double c[] =
3021 -5.504751339936943e-03, -2.279687217114118e-01,
3022 -1.697592457770869e+00, -1.802933168781950e+00,
3023 3.093354679843505e+00, 2.077595676404383e+00
3025 static const double d[] =
3027 7.784695709041462e-03, 3.224671290700398e-01,
3028 2.445134137142996e+00, 3.754408661907416e+00
3031 static const double spi2 = 8.862269254527579e-01;
3032 static const double pbreak = 0.95150;
3033 double ax = fabs (x), y;
3039 const double q = 0.5 *
x, r = q*q;
3040 const double yn = (((((a[0]*r + a[1])*r + a[2])*r + a[3])*r + a[4])*r + a[5])*q;
3041 const double yd = ((((b[0]*r + b[1])*r + b[2])*r + b[3])*r + b[4])*r + 1.0;
3047 const double q = sqrt (-2*log (0.5*(1-ax)));
3048 const double yn = ((((c[0]*q + c[1])*q + c[2])*q + c[3])*q + c[4])*q + c[5];
3049 const double yd = (((d[0]*q + d[1])*q + d[2])*q + d[3])*q + 1.0;
3050 y = yn / yd *
signum (-x);
3060 double u = (
erf (y) -
x) * spi2 * exp (y*y);
3084 static const double a[] =
3086 -2.806989788730439e+01, 1.562324844726888e+02,
3087 -1.951109208597547e+02, 9.783370457507161e+01,
3088 -2.168328665628878e+01, 1.772453852905383e+00
3090 static const double b[] =
3092 -5.447609879822406e+01, 1.615858368580409e+02,
3093 -1.556989798598866e+02, 6.680131188771972e+01,
3094 -1.328068155288572e+01
3096 static const double c[] =
3098 -5.504751339936943e-03, -2.279687217114118e-01,
3099 -1.697592457770869e+00, -1.802933168781950e+00,
3100 3.093354679843505e+00, 2.077595676404383e+00
3102 static const double d[] =
3104 7.784695709041462e-03, 3.224671290700398e-01,
3105 2.445134137142996e+00, 3.754408661907416e+00
3108 static const double spi2 = 8.862269254527579e-01;
3109 static const double pbreak_lo = 0.04850;
3110 static const double pbreak_hi = 1.95150;
3114 if (x >= pbreak_lo && x <= pbreak_hi)
3117 const double q = 0.5*(1-
x), r = q*q;
3118 const double yn = (((((a[0]*r + a[1])*r + a[2])*r + a[3])*r + a[4])*r + a[5])*q;
3119 const double yd = ((((b[0]*r + b[1])*r + b[2])*r + b[3])*r + b[4])*r + 1.0;
3122 else if (x > 0.0 && x < 2.0)
3125 const double q = x < 1 ? sqrt (-2*log (0.5*x)) : sqrt (-2*log (0.5*(2-x)));
3126 const double yn = ((((c[0]*q + c[1])*q + c[2])*q + c[3])*q + c[4])*q + c[5];
3127 const double yd = (((d[0]*q + d[1])*q + d[2])*q + d[3])*q + 1.0;
3142 double u = (
erf (y) - (1-
x)) * spi2 * exp (y*y);
3176 betain (
double x,
double p,
double q,
double beta,
bool& err)
3178 double acu = 0.1E-14, ai, cx;
3181 double pp, psq, qq, rx, temp, term, value, xx;
3188 if ((p <= 0.0 || q <= 0.0) || (x < 0.0 || 1.0 < x))
3196 if (x == 0.0 || x == 1.0)
3225 ns =
static_cast<int> (qq + cx * psq);
3238 term = term * temp * rx / (pp + ai);
3239 value = value + term;
3242 if (temp <= acu && temp <= acu * value)
3244 value = value * exp (pp * log (xx)
3245 + (qq - 1.0) * log (cx) - beta) / pp;
3249 value = 1.0 - value;
3295 double a, acu, adj, fpu, g, h;
3298 double pp, prev, qq, r, s, sae = -37.0, sq, t, tx, value,
w, xin, ycur, yprev;
3302 fpu =
pow (10.0, sae);
3307 if (p <= 0.0 || q <= 0.0)
3309 (*current_liboctave_error_handler)
3310 (
"betaincinv: wrong parameters");
3313 if (y < 0.0 || 1.0 < y)
3315 (*current_liboctave_error_handler)
3316 (
"betaincinv: wrong parameter Y");
3319 if (y == 0.0 || y == 1.0)
3343 r = sqrt (- log (a * a));
3345 ycur = r - (2.30753 + 0.27061 * r) / (1.0 + (0.99229 + 0.04481 * r) * r);
3347 if (1.0 < pp && 1.0 < qq)
3349 r = (ycur * ycur - 3.0) / 6.0;
3350 s = 1.0 / (pp + pp - 1.0);
3351 t = 1.0 / (qq + qq - 1.0);
3353 w = ycur * sqrt (h + r) / h - (t - s) * (r + 5.0 / 6.0 - 2.0 / (3.0 * h));
3354 value = pp / (pp + qq * exp (w + w));
3359 t = 1.0 / (9.0 * qq);
3360 t = r *
pow (1.0 - t + ycur * sqrt (t), 3);
3364 value = 1.0 - exp ((log ((1.0 - a) * qq) + beta) / qq);
3368 t = (4.0 * pp + r - 2.0) / t;
3372 value = exp ((log (a * pp) + beta) / pp);
3376 value = 1.0 - 2.0 / (t + 1.0);
3400 iex =
std::max (- 5.0 / pp / pp - 1.0 /
pow (a, 0.2) - 13.0, sae);
3402 acu =
pow (10.0, iex);
3406 ycur =
betain (value, pp, qq, beta, err);
3414 ycur = (ycur - a) * exp (beta + r * log (xin) + t * log (1.0 - xin));
3416 if (ycur * yprev <= 0.0)
3434 if (0.0 <= tx && tx <= 1.0)
3446 value = 1.0 - value;
3451 if (ycur * ycur <= acu)
3455 value = 1.0 - value;
3460 if (tx != 0.0 && tx != 1.0)
3479 value = 1.0 - value;
3523 if (dv == b.
dims ())
3562 if (dv == b.
dims ())
3585 if (dv == a.
dims ())
3609 if (dv == a.
dims () && dv == b.
dims ())
3627 ellipj (
double u,
double m,
double& sn,
double& cn,
double& dn,
double& err)
3629 static const int Nmax = 16;
3630 double m1, t=0, si_u, co_u, se_u, ta_u, b, c[Nmax], a[Nmax], phi;
3635 (*current_liboctave_warning_handler)
3636 (
"ellipj: expecting 0 <= M <= 1");
3641 double sqrt_eps = sqrt (std::numeric_limits<double>::epsilon ());
3647 t = 0.25*m*(u - si_u*co_u);
3648 sn = si_u - t * co_u;
3649 cn = co_u + t * si_u;
3650 dn = 1 - 0.5*m*si_u*si_u;
3652 else if ((1 - m) < sqrt_eps)
3660 sn = ta_u + 0.25*m1*(si_u*co_u - u)*se_u*se_u;
3661 cn = se_u - 0.25*m1*(si_u*co_u - u)*ta_u*se_u;
3662 dn = se_u + 0.25*m1*(si_u*co_u + u)*ta_u*se_u;
3671 for (n = 1; n < Nmax; ++n)
3673 a[n] = (a[n - 1] + b)/2;
3674 c[n] = (a[n - 1] - b)/2;
3675 b = sqrt (a[n - 1]*b);
3676 if (c[n]/a[n] < std::numeric_limits<double>::epsilon ())
break;
3684 for (ii = 1; n > 0; ii = ii*2, --n) ;
3686 for (n = Nn; n > 0; --n)
3689 phi = (
asin ((c[n]/a[n])* sin (phi)) + phi)/2;
3693 dn = cn/cos (t - phi);
3698 ellipj (
const Complex& u,
double m, Complex& sn, Complex& cn, Complex& dn,
3701 double m1 = 1 - m, ss1, cc1, dd1;
3714 double ss, cc, dd, ddd;
3717 ddd = cc1*cc1 + m*ss*ss*ss1*ss1;
3718 sn =
Complex (ss*dd1/ddd, cc*dd*ss1*cc1/ddd);
3719 cn =
Complex (cc*cc1/ddd, -ss*dd*ss1*dd1/ddd);
3720 dn =
Complex (dd*cc1*dd1/ddd, -m*ss*cc*ss1/ddd);