public static MultiPrecision <N> BesselI(MultiPrecision <N> nu, MultiPrecision <N> x) { if (MultiPrecision <N> .Abs(nu) > 64) { throw new ArgumentOutOfRangeException( nameof(nu), "In the calculation of the Bessel function, nu with an absolute value greater than 64 is not supported." ); } if (nu.IsNaN || x.IsNaN || x.Sign == Sign.Minus) { return(MultiPrecision <N> .NaN); } if (nu.Sign == Sign.Minus && nu == MultiPrecision <N> .Truncate(nu)) { return(BesselI(MultiPrecision <N> .Abs(nu), x)); } if (nu - MultiPrecision <N> .Point5 == MultiPrecision <N> .Floor(nu)) { long n = (long)MultiPrecision <N> .Floor(nu); if (n >= -2 && n < 2) { MultiPrecision <Plus1 <N> > x_ex = x.Convert <Plus1 <N> >(); MultiPrecision <Plus1 <N> > r = MultiPrecision <Plus1 <N> > .Sqrt2 / MultiPrecision <Plus1 <N> > .Sqrt(MultiPrecision <Plus1 <N> > .PI *x_ex); if (n == -2) { return(-(r * (MultiPrecision <Plus1 <N> > .Cosh(x_ex) / x_ex - MultiPrecision <Plus1 <N> > .Sinh(x_ex))).Convert <N>()); } if (n == -1) { return((r * MultiPrecision <Plus1 <N> > .Cosh(x_ex)).Convert <N>()); } if (n == 0) { MultiPrecision <N> y = (r * MultiPrecision <Plus1 <N> > .Sinh(x_ex)).Convert <N>(); return(y.IsNormal ? y : 0); } if (n == 1) { MultiPrecision <N> y = -(r * (MultiPrecision <Plus1 <N> > .Sinh(x_ex) / x_ex - MultiPrecision <Plus1 <N> > .Cosh(x_ex))).Convert <N>(); return(y.IsNormal ? y : 0); } } } if (x < Consts.BesselIK.ApproxThreshold) { return(BesselINearZero(nu, x).Convert <N>()); } else { return(BesselILimit(nu, x).Convert <N>()); } }
public void CoshTest() { foreach (MultiPrecision <Pow2.N8> x in TestTool.AllRangeSet <Pow2.N8>()) { MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .Cosh(x); Console.WriteLine(x); Console.WriteLine(y); TestTool.Tolerance(Math.Cosh((double)x), y, ignore_sign: true); } }