Documentation
¶
Overview ¶
Package bigmath implements arbitrary-precision arithmetic (big numbers) methods to parallel much of what is found in [https://pkg.go.dev/math](math)
Index ¶
- Variables
- func Acos(x *big.Float) *big.Float
- func Acosh(x *big.Float) *big.Float
- func Acot(x *big.Float) *big.Float
- func Acoth(x *big.Float) *big.Float
- func Acsc(x *big.Float) *big.Float
- func Acsch(x *big.Float) *big.Float
- func Asec(x *big.Float) *big.Float
- func Asech(x *big.Float) *big.Float
- func Asin(x *big.Float) *big.Float
- func Asinh(x *big.Float) *big.Float
- func Atan(x *big.Float) *big.Float
- func Atanh(x *big.Float) *big.Float
- func ComputeE(precision uint) *big.Float
- func ComputePi(precision uint) *big.Float
- func Cos(x *big.Float) *big.Float
- func Cosh(x *big.Float) *big.Float
- func Cot(x *big.Float) *big.Float
- func Coth(x *big.Float) *big.Float
- func Csc(x *big.Float) *big.Float
- func Csch(x *big.Float) *big.Float
- func E() *big.Float
- func Exp(x *big.Float) *big.Float
- func Exp2(x *big.Float) *big.Float
- func Factorial(n int64) *big.Int
- func FactorialFloat(x *big.Float) *big.Float
- func Gamma(x *big.Float) *big.Float
- func GammaFloat64(x float64) *big.Float
- func Log(x *big.Float) *big.Float
- func Pi() *big.Float
- func Pow(x, y *big.Float) *big.Float
- func PowFloat64(x, y float64) *big.Float
- func PowInt(x *big.Float, n int64) *big.Float
- func Sec(x *big.Float) *big.Float
- func Sech(x *big.Float) *big.Float
- func Sin(x *big.Float) *big.Float
- func Sinh(x *big.Float) *big.Float
- func Tan(x *big.Float) *big.Float
- func Tanh(x *big.Float) *big.Float
Constants ¶
This section is empty.
Variables ¶
var ( BernoulliNumbers = []big.Float{ *big.NewFloat(1), *big.NewFloat(1.0 / 2), *big.NewFloat(1.0 / 6), *big.NewFloat(-1.0 / 30), *big.NewFloat(1.0 / 42), *big.NewFloat(-1.0 / 30), *big.NewFloat(5.0 / 66), *big.NewFloat(-691.0 / 2730), *big.NewFloat(7.0 / 6), *big.NewFloat(-3617.0 / 510), *big.NewFloat(43867.0 / 798), *big.NewFloat(-174611.0 / 330), *big.NewFloat(854513.0 / 138), *big.NewFloat(-236364091.0 / 2730), *big.NewFloat(8553103.0 / 6), *big.NewFloat(-23749461029.0 / 870), *big.NewFloat(8615841276005.0 / 14322), *big.NewFloat(-7709321041217.0 / 510), *big.NewFloat(2577687858367.0 / 6), *big.NewFloat(-26315271553053477373.0 / 1919190), *big.NewFloat(2929993913841559.0 / 6), *big.NewFloat(-261082718496449122051.0 / 13530), *big.NewFloat(1520097643918070802691.0 / 1806), *big.NewFloat(-27833269579301024235023.0 / 690), *big.NewFloat(596451111593912163277961.0 / 282), *big.NewFloat(-5609403368997817686249127547.0 / 46410), *big.NewFloat(495057205241079648212477525.0 / 66), *big.NewFloat(-801165718135489957347924991853.0 / 1590), *big.NewFloat(29149963634884862421418123812691.0 / 798), *big.NewFloat(-2479392929313226753685415739663229.0 / 870), *big.NewFloat(84483613348880041862046775994036021.0 / 354), *big.NewFloat(-1215233140483755572040304994079820246041491.0 / 56786730), } )
Bernoulli B2n numbers are used in some Taylor series expansions.
Functions ¶
func Acos ¶
Acos returns the arccosine, in radians, of x.
The special case is:
Acos(x) = NaN if x < -1 or x > 1
func Acosh ¶
Acosh returns the inverse hyperbolic cosine of x.
The special cases are:
Acosh(+Inf) = +Inf Acosh(x) = NaN if x < 1 Acosh(NaN) = NaN
func Acoth ¶
Acoth calculates inverse hyperbolic cotangent using the formula: acoth(x) = atanh(1/x) This is a placeholder implementation.
func Acsch ¶
Acsch calculates inverse hyperbolic cosecant using the formula: acsch(x) = asinh(1/x) This is a placeholder implementation.
func Asech ¶
Asech calculates inverse hyperbolic secant using the formula: asech(x) = acosh(1/x) This is a placeholder implementation.
func Asin ¶
Asin returns the arcsine, in radians, of x.
The special cases are:
Asin(±0) = ±0 Asin(x) = NaN if x < -1 or x > 1
func Asinh ¶
Asinh returns the hyperbolic sine of x.
The special cases are:
Asinh(±0) = ±0 Asinh(±Inf) = ±Inf Asinh(NaN) = NaN
func Atan ¶
Atan returns the arctangent, in radians, of x.
The special cases are:
Atan(±0) = ±0 Atan(±Inf) = ±Pi/2 Atan(NaN) = NaN
func Atanh ¶
Atanh returns the inverse hyperbolic arc tangent of x.
The special cases are:
Atanh(1) = +Inf Atanh(±0) = ±0 Atanh(-1) = -Inf Atanh(x) = NaN if x < -1 or x > 1 Atanh(NaN) = NaN
func Cos ¶
Cos returns the cosine of the radian argument x.
The special cases are:
Cos(±Inf) = NaN Cos(NaN) = NaN
func Cosh ¶
Cosh returns the hyperbolic cosine of x.
The special cases are:
Cosh(±0) = 1 Cosh(±Inf) = +Inf Cosh(NaN) = NaN
func Coth ¶
Coth calculates hyperbolic cotangent using the formula: coth(x) = cosh(x)/sinh(x) This is a placeholder implementation.
func Csch ¶
Csch calculates hyperbolic cosecant using the formula: csch(x) = 1/sinh(x) This is a placeholder implementation.
func E ¶
E returns a copy of the precomputed high-precision e value.
Because we can't make const *big.Floats, and don't want someone downstream altering the value, we return a copy.
func Exp ¶
Exp returns e**x, the base-e exponential of x.
The special cases are:
Exp(+Inf) = +Inf Exp(NaN) = NaN
Very large values no longer overflow to 0 or +Inf. Very small values no longer underflow to 1.
For the time being, there is an explicit upper bound for x of ~700,000 beyond which we choose to call it Infinite instead of looping excessively.
func Exp2 ¶
Exp2 returns 2**x, the base-2 exponential of x.
The special cases are:
Exp2(+Inf) = +Inf Exp2(NaN) = NaN
func Factorial ¶
Factorial calculates n! using big.Int math to ensure no overflow.
big.Int does not have a concept of Inf or NaN, so the best we can do for negatives is return 0.
func FactorialFloat ¶
FactorialFloat is a function that returns the factorial of a given big.Float. For integer values, computes n! = n * (n-1) * ... * 2 * 1 For non-integer values, uses the Gamma function property: n! = Gamma(n+1)
Negative values will return +Inf.
func Gamma ¶
Gamma returns the Gamma function of x using *big.Float arithmetic.
For positive integers n, Γ(n) = (n-1)!
Uses Stirling's approximation for large values and Lanczos approximation for smaller values.
The special cases are:
Gamma(+Inf) = +Inf Gamma(+0) = +Inf Gamma(-0) = -Inf Gamma(x) = NaN for integer x < 0 Gamma(-Inf) = NaN Gamma(NaN) = NaN
func GammaFloat64 ¶
GammaFloat64 computes the Gamma function Γ(x) by converting the float64 to a *big.Float and then using the Gamma() method for values that would otherwise have led to overflow in float64.
For positive integers n, Γ(n) = (n-1)!
func Log ¶
Log computes natural logarithm using a collection of methods depending in the input value and precision.
func Pi ¶
Pi returns a copy of the precomputed high-precision π value.
Because we can't make const *big.Floats, and don't want someone downstream altering the value, we return a copy.
func Pow ¶
Pow returns x**y, the base-x exponential of y using *big.Float arithmetic.
Special cases are (in order):
Pow(x, ±0) = 1 for any x Pow(1, y) = 1 for any y Pow(x, 1) = x for any x Pow(NaN, y) = NaN Pow(x, NaN) = NaN Pow(±0, y) = ±Inf for y an odd integer < 0 Pow(±0, -Inf) = +Inf Pow(±0, +Inf) = +0 Pow(±0, y) = +Inf for finite y < 0 and not an odd integer Pow(±0, y) = ±0 for y an odd integer > 0 Pow(±0, y) = +0 for finite y > 0 and not an odd integer Pow(-1, ±Inf) = 1 Pow(x, +Inf) = +Inf for |x| > 1 Pow(x, -Inf) = +0 for |x| > 1 Pow(x, +Inf) = +0 for |x| < 1 Pow(x, -Inf) = +Inf for |x| < 1 Pow(+Inf, y) = +Inf for y > 0 Pow(+Inf, y) = +0 for y < 0 Pow(-Inf, y) = Pow(-0, -y) Pow(x, y) = NaN for finite x < 0 and finite non-integer y
func PowFloat64 ¶
PowFloat64 returns x**y, the base-x exponential of y from float64 inputs returning a *big.Float. Useful when x**y would overflow a float64 normally.
Special cases are:
PowFloat64(x, ±0) = 1 for any x PowFloat64(1, y) = 1 for any y PowFloat64(x, 1) = x for any x PowFloat64(NaN, y) = ErrNaN PowFloat64(x, NaN) = ErrNaN Pow(±0, -Inf) = +Inf Pow(±0, +Inf) = +0 Pow(±0, y) = +Inf for finite y < 0 and not an odd integer Pow(±0, y) = +0 for finite y > 0 and not an odd integer Pow(±0, y) = ±Inf for y an odd integer < 0 Pow(±0, y) = ±0 for y an odd integer > 0 Pow(-1, ±Inf) = 1 Pow(x, +Inf) = +Inf for |x| > 1 Pow(x, -Inf) = +0 for |x| > 1 Pow(x, +Inf) = +0 for |x| < 1 Pow(x, -Inf) = +Inf for |x| < 1 Pow(+Inf, y) = +Inf for y > 0 Pow(+Inf, y) = +0 for y < 0 Pow(-Inf, y) = Pow(-0, -y) Pow(x, y) = ErrNan for finite x < 0 and finite non-integer y
func Sech ¶
Sech calculates hyperbolic secant using the formula: sech(x) = 1/cosh(x) This is a placeholder implementation.
func Sin ¶
Sin returns the sine of the radian argument x.
Choose the best available algorithm for maximum precision. Automatically selects between Taylor series, Chebyshev polynomials, minimax approximation, and CORDIC based on argument size and precision requirements.
The special cases are:
Sin(±0) = ±0 Sin(±Inf) = NaN Sin(NaN) = NaN
func Sinh ¶
Sinh returns the hyperbolic sine of x.
The special cases are:
Sinh(±0) = ±0 Sinh(±Inf) = ±Inf Sinh(NaN) = NaN
Types ¶
This section is empty.