math

package
v0.0.0-...-00de7ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause Imports: 1 Imported by: 7

Documentation

Overview

Package math implements various useful mathematical functions and constants.

Deprecated: the functionality has been moved into the decimal

package itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Acos

func Acos(z, x *decimal.Big) *decimal.Big

Acos returns the arccosine, in radians, of x.

Range:

Input: -1 <= x <= 1
Output: 0 <= Acos(x) <= pi

Special cases:

Acos(NaN)  = NaN
Acos(±Inf) = NaN
Acos(x)    = NaN if x < -1 or x > 1
Acos(-1)   = pi
Acos(1)    = 0

func Asin

func Asin(z, x *decimal.Big) *decimal.Big

Asin returns the arcsine, in radians, of x.

Range:

Input: -1 <= x <= 1
Output: -pi/2 <= Asin(x) <= pi/2

Special cases:

Asin(NaN)  = NaN
Asin(±Inf) = NaN
Asin(x)    = NaN if x < -1 or x > 1
Asin(±1)   = ±pi/2

func Atan

func Atan(z, x *decimal.Big) *decimal.Big

Atan returns the arctangent, in radians, of x.

Range:

Input: all real numbers
Output: -pi/2 <= Atan(x) <= pi/2

Special cases:

Atan(NaN)  = NaN
Atan(±Inf) = ±x * pi/2

func Atan2

func Atan2(z, y, x *decimal.Big) *decimal.Big

Atan2 calculates arctan of y/x and uses the signs of y and x to determine the valid quadrant

Range:

y input: all real numbers
x input: all real numbers
Output: -pi < Atan2(y, x) <= pi

Special cases:

Atan2(NaN, NaN)      = NaN
Atan2(y, NaN)        = NaN
Atan2(NaN, x)        = NaN
Atan2(±0, x >=0)     = ±0
Atan2(±0, x <= -0)   = ±pi
Atan2(y > 0, 0)      = +pi/2
Atan2(y < 0, 0)      = -pi/2
Atan2(±Inf, +Inf)    = ±pi/4
Atan2(±Inf, -Inf)    = ±3pi/4
Atan2(y, +Inf)       = 0
Atan2(y > 0, -Inf)   = +pi
Atan2(y < 0, -Inf)   = -pi
Atan2(±Inf, x)       = ±pi/2
Atan2(y, x > 0)      = Atan(y/x)
Atan2(y >= 0, x < 0) = Atan(y/x) + pi
Atan2(y < 0, x < 0)  = Atan(y/x) - pi

func BinarySplit

func BinarySplit(z *decimal.Big, ctx decimal.Context, start, stop uint64, A, P, B, Q SplitFunc) *decimal.Big

BinarySplit sets z to the result of the binary splitting formula and returns z. The formula is defined as:

    ∞    a(n)p(0) ... p(n)
S = Σ   -------------------
    n=0  b(n)q(0) ... q(n)

It should only be used when the number of terms is known ahead of time. If start is not in [start, stop) or stop is not in (start, stop], BinarySplit will panic.

func BinarySplitDynamic

func BinarySplitDynamic(ctx decimal.Context, A, P, B, Q SplitFunc) *decimal.Big

BinarySplitDynamic sets z to the result of the binary splitting formula. It should be used when the number of terms is not known ahead of time. For more information, See BinarySplit.

func Ceil

func Ceil(z, x *decimal.Big) *decimal.Big

Ceil sets z to the least integer value greater than or equal to x and returns z.

func Cos

func Cos(z, x *decimal.Big) *decimal.Big

Cos returns the cosine, in radians, of x.

Range:

Input: all real numbers
Output: -1 <= Cos(x) <= 1

Special cases:

Cos(NaN)  = NaN
Cos(±Inf) = NaN

func E

func E(z *decimal.Big) *decimal.Big

E sets z to the mathematical constant e and returns z.

func Exp

func Exp(z, x *decimal.Big) *decimal.Big

Exp sets z to e**x and returns z.

func Floor

func Floor(z, x *decimal.Big) *decimal.Big

Floor sets z to the greatest integer value less than or equal to x and returns z.

func Hypot

func Hypot(z, p, q *decimal.Big) *decimal.Big

Hypot sets z to Sqrt(p*p + q*q) and returns z.

func Lentz

func Lentz(z *decimal.Big, g Generator) *decimal.Big

Lentz sets z to the result of the continued fraction provided by the Generator and returns z.

The continued fraction should be represented as such:

                     a1
f(x) = b0 + --------------------
                       a2
            b1 + ---------------
                          a3
                 b2 + ----------
                            a4
                      b3 + -----
                             ...

Or, equivalently:

             a1   a2   a3
f(x) = b0 + ---- ---- ----
             b1 + b2 + b3 + ···

If terms need to be subtracted, the a_N terms should be negative. To compute a continued fraction without b_0, divide the result by a_1.

If the first call to the Generator's Next method returns false, the result of Lentz is undefined.

Note: the accuracy of the result may be affected by the precision of intermediate results. If larger precision is desired, it may be necessary for the Generator to implement the Lentzer interface and set a higher precision for f, Δ, C, and D.

func Log

func Log(z, x *decimal.Big) *decimal.Big

Log sets z to the natural logarithm of x and returns z.

func Log10

func Log10(z, x *decimal.Big) *decimal.Big

Log10 sets z to the common logarithm of x and returns z.

func Pi

func Pi(z *decimal.Big) *decimal.Big

Pi sets z to the mathematical constant pi and returns z.

func Pow

func Pow(z, x, y *decimal.Big) *decimal.Big

Pi sets z to the mathematical constant pi and returns z.

func Sin

func Sin(z, x *decimal.Big) *decimal.Big

Sin returns the sine, in radians, of x.

Range:

Input: all real numbers
Output: -1 <= Sin(x) <= 1

Special cases:

Sin(NaN) = NaN
Sin(Inf) = NaN

func Sqrt

func Sqrt(z, x *decimal.Big) *decimal.Big

Sqrt sets z to the square root of x and returns z.

func Tan

func Tan(z, x *decimal.Big) *decimal.Big

Tan returns the tangent, in radians, of x.

Range:

Input: -pi/2 <= x <= pi/2
Output: all real numbers

Special cases:

Tan(NaN) = NaN
Tan(±Inf) = NaN

func Wallis

func Wallis(z *decimal.Big, g Generator) *decimal.Big

Wallis sets z to the result of the continued fraction provided by the Generator and returns z.

The fraction is evaluated in a top-down manner, using the recurrence algorithm discovered by John Wallis. For more information on continued fraction representations, see the Lentz function.

Types

type Contexter

type Contexter = decimal.Contexter

type Generator

type Generator = decimal.Generator

type Lentzer

type Lentzer = decimal.Lentzer

type SplitFunc

type SplitFunc = decimal.SplitFunc

type Term

type Term = decimal.Term

type Walliser

type Walliser = decimal.Walliser

Directories

Path Synopsis
Package debug provides simple routines for debugging continued fractions.
Package debug provides simple routines for debugging continued fractions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL