Skip to content

tk-yoshimura/MultiPrecision

Repository files navigation

MultiPrecision

MultiPrecision Arithmetic Implements

Requirement

.NET 8.0

AVX2 suppoted CPU. (Intel:Haswell(2013)-, AMD:Excavator(2015)-)

Install

Download DLL
Download Nuget

More Functions ?

DoubleDouble (31-32 digits)

Spec

Exponent : ±2147483647
Mantissa : 128-32768 bits
Round: half away from zero
MaxValue: ±8.808065x10^646456992

Types

type mantissa bits significant digits note
MultiPrecision<Pow2.N4> 128 34 Fastest
MultiPrecision<Pow2.N8> 256 73 Fast
MultiPrecision<Pow2.N16> 512 150 Standard
MultiPrecision<Pow2.N32> 1024 304
MultiPrecision<Pow2.N64> 2048 612 Slow
MultiPrecision<Pow2.N128> 4096 1229
MultiPrecision<Pow2.N256> 8192 2462 Very slow
MultiPrecision<Pow2.N512> 16384 4928
MultiPrecision<Pow2.N1024> 32768 9860 Not recommended
MultiPrecision<N> Length x 32 Length x 9.6 - 4 public struct N : IConstant {
  public int Value => Length;
}

Functions

function domain mantissa error bits note
MultiPrecision<N>.Sqrt(x) [0,+inf) 1
MultiPrecision<N>.Cbrt(x) (-inf,+inf) 1
MultiPrecision<N>.Log2(x) (0,+inf) 0
MultiPrecision<N>.Log(x) (0,+inf) 1
MultiPrecision<N>.Log10(x) (0,+inf) 1
MultiPrecision<N>.Log1p(x) (-1,+inf) 1 log(1+x)
MultiPrecision<N>.Pow2(x) (-inf,+inf) 0
MultiPrecision<N>.Pow(x, y) (-inf,+inf) 1
MultiPrecision<N>.Pow10(x) (-inf,+inf) 1
MultiPrecision<N>.Exp(x) (-inf,+inf) 1
MultiPrecision<N>.Expm1(x) (-inf,+inf) 1 exp(x)-1
MultiPrecision<N>.Sin(x) (-inf,+inf) 1
MultiPrecision<N>.Cos(x) (-inf,+inf) 1
MultiPrecision<N>.Tan(x) (-inf,+inf) 2
MultiPrecision<N>.SinPi(x) (-inf,+inf) 0 sin(πx)
MultiPrecision<N>.CosPi(x) (-inf,+inf) 0 cos(πx)
MultiPrecision<N>.TanPi(x) (-inf,+inf) 1 tan(πx)
MultiPrecision<N>.Sinh(x) (-inf,+inf) 2
MultiPrecision<N>.Cosh(x) (-inf,+inf) 2
MultiPrecision<N>.Tanh(x) (-inf,+inf) 2
MultiPrecision<N>.Asin(x) [-1,1] 2 Accuracy deteriorates near x=-1,1.
MultiPrecision<N>.Acos(x) [-1,1] 2 Accuracy deteriorates near x=-1,1.
MultiPrecision<N>.Atan(x) (-inf,+inf) 2
MultiPrecision<N>.Atan2(y, x) (-inf,+inf) 2
MultiPrecision<N>.Asinh(x) (-inf,+inf) 2
MultiPrecision<N>.Acosh(x) [1,+inf) 2
MultiPrecision<N>.Atanh(x) (-1,1) 4 Accuracy deteriorates near x=-1,1.
MultiPrecision<N>.Sinc(x, normalized) (-inf,+inf) 2 normalized: x -> πx
MultiPrecision<N>.Sinhc(x) (-inf,+inf) 3
MultiPrecision<N>.Erf(x) (-1,1) 2 Length ≤ 256
MultiPrecision<N>.Erfc(x) (0,2) 2 Length ≤ 256
MultiPrecision<N>.InverseErf(x) (-1,1) 2 Length ≤ 256
MultiPrecision<N>.InverseErfc(x) (0,2) 4 Length ≤ 256
MultiPrecision<N>.LogGamma(x) (0,+inf) 2 Accuracy deteriorates near x=0.
Length ≤ 256
MultiPrecision<N>.Gamma(x) (-inf,+inf) 2 Accuracy deteriorates near non-positive intergers.
Length ≤ 256
MultiPrecision<N>.Digamma(x) (-inf,+inf) 2 Accuracy deteriorates near non-positive intergers and zero points.
Length ≤ 256
MultiPrecision<N>.BesselJ(nu, z) (-inf,+inf) 2 Accuracy deteriorates near zero points.
(error ≤ 2^-(mantissa bits + 64))
Length ≤ 65
abs(nu) ≤ 64
MultiPrecision<N>.BesselY(nu, z) (-inf,+inf) 2 Accuracy deteriorates near zero points.
(error ≤ 2^-(mantissa bits + 64))
Length ≤ 65
abs(nu) ≤ 64
MultiPrecision<N>.BesselI(nu, z) [0,+inf) 2 Length ≤ 65
abs(nu) ≤ 64
MultiPrecision<N>.BesselK(nu, z) [0,+inf) 2 Length ≤ 65
abs(nu) ≤ 64
MultiPrecision<N>.Jinc(x) (-inf,+inf) 3
MultiPrecision<N>.EllipticK(m) [0,1] 1 k: elliptic modulus, m=k^2
MultiPrecision<N>.EllipticE(m) [0,1] 1 k: elliptic modulus, m=k^2
MultiPrecision<N>.EllipticPi(n, m) [0,1] 1 k: elliptic modulus, m=k^2
MultiPrecision<N>.Ldexp(x, y) (-inf,+inf) N/A
MultiPrecision<N>.Random(random) N/A N/A generation uniform random [0, 1)
MultiPrecision<N>.Min(x, y) N/A N/A
MultiPrecision<N>.Max(x, y) N/A N/A
MultiPrecision<N>.Floor(x) N/A N/A
MultiPrecision<N>.Ceiling(x) N/A N/A
MultiPrecision<N>.Round(x) N/A N/A
MultiPrecision<N>.Truncate(x) N/A N/A
IEnumerable<MultiPrecision<N>>.Sum() N/A N/A kahan summation
IEnumerable<MultiPrecision<N>>.Average() N/A N/A kahan summation
IEnumerable<MultiPrecision<N>>.Variance() N/A N/A population variance
IEnumerable<MultiPrecision<N>>.Min() N/A N/A
IEnumerable<MultiPrecision<N>>.Max() N/A N/A

Constants

constant value note
MultiPrecision<N>.Pi 3.141592653589793238462... Pi
MultiPrecision<N>.E 2.718281828459045235360... Napier's E
MultiPrecision<N>.Sqrt2 1.414213562373095048801... Sqrt(2)
MultiPrecision<N>.Lg2 0.301029995663981195213... log10(2)
lg:=log10 (ISO 80000-2-12.6)
MultiPrecision<N>.Lb10 3.321928094887362347870... log2(10)
lb:=log2 (ISO 80000-2-12.7)
MultiPrecision<N>.Ln2 0.693147180559945309417... log(2)
ln:=log (ISO 80000-2-12.5)
MultiPrecision<N>.LbE 1.442695040888963407359... log2(e)
MultiPrecision<N>.EulerGamma 0.577215664901532860606... Euler's Gamma
MultiPrecision<N>.Zeta3 1.202056903159594285399... ζ(3), Apery const.
MultiPrecision<N>.Zeta5 1.036927755143369926331... ζ(5)
MultiPrecision<N>.Zeta7 1.008349277381922826839... ζ(7)

Sequence

sequence note
MultiPrecision<N>.TaylorSequence Taylor, 1/n!
MultiPrecision<N>.BernoulliSequence Bernoulli, B(2k)
MultiPrecision<N>.StirlingSequence Stirling, Gamma convergent series, Bayes(1763)
MultiPrecision<N>.HarmonicNumber HarmonicNumber, H_n

Coefficient

coefficient note
MultiPrecision<N>.ChebyshevCoef Chebyshev, C(n, m)

Casts

  • long (accurately)
MultiPrecision<N> v0 = 123;
long n0 = (long)v0;
  • double (accurately)
MultiPrecision<N> v1 = 0.5;
double n1 = (double)v1;
  • decimal (approximately)
MultiPrecision<N> v1 = 0.1m;
decimal n1 = (decimal)v1;
  • string (approximately)
MultiPrecision<N> v2 = "3.14e0";
string s0 = v2.ToString();
string s1 = v2.ToString("E8");
string s2 = $"{v2:E8}";

I/O

BinaryWriter, BinaryReader

Licence

MIT

Author

T.Yoshimura