Documentation ¶
Index ¶
- Constants
- func Cbrt(z, x *inf.Dec, s inf.Scale) *inf.Dec
- func Exp(z, n *inf.Dec, s inf.Scale) *inf.Dec
- func Float64FromDec(dec *inf.Dec) (float64, error)
- func Log(z *inf.Dec, x *inf.Dec, s inf.Scale) *inf.Dec
- func Log10(z *inf.Dec, x *inf.Dec, s inf.Scale) *inf.Dec
- func LogN(z *inf.Dec, x *inf.Dec, n *inf.Dec, s inf.Scale) *inf.Dec
- func Mod(z, x, y *inf.Dec) *inf.Dec
- func NewDecFromFloat(f float64) *inf.Dec
- func NumDigits(bi *big.Int, tmp []byte) (int, []byte)
- func Pow(z, x, y *inf.Dec, s inf.Scale) (*inf.Dec, error)
- func PowerOfTenDec(pow int) *inf.Dec
- func PowerOfTenInt(pow int) *big.Int
- func SetFromFloat(z *inf.Dec, f float64) *inf.Dec
- func Sqrt(z, x *inf.Dec, s inf.Scale) *inf.Dec
Constants ¶
const Precision = 16
Precision defines the minimum precision all inexact decimal calculations should attempt to achieve.
Variables ¶
This section is empty.
Functions ¶
func Cbrt ¶
func Cbrt(z, x *inf.Dec, s inf.Scale) *inf.Dec
Cbrt calculates the cube root of x to the specified scale and stores the result in z, which is also the return value.
The cube root calculation is implemented using Newton-Raphson method. We start with an initial estimate for cbrt(d), and then iterate:
x_{n+1} = 1/3 * ( 2 * x_n + (d / x_n / x_n) ).
func Exp ¶
func Exp(z, n *inf.Dec, s inf.Scale) *inf.Dec
Exp computes (e^n) (where n = a*b with a being an integer and b < 1) to the specified scale and stores the result in z, which is also the return value.
func Float64FromDec ¶
Float64FromDec converts a decimal to a float64 value, returning the value and any error that occurred. This converson exposes a possible loss of information.
func Log ¶
func Log(z *inf.Dec, x *inf.Dec, s inf.Scale) *inf.Dec
Log computes the natural log of x using the Maclaurin series for log(1-x) to the specified scale and stores the result in z, which is also the return value. The function will panic if x is a negative number.
func Log10 ¶
func Log10(z *inf.Dec, x *inf.Dec, s inf.Scale) *inf.Dec
Log10 computes the log of x with base 10 to the specified scale and stores the result in z, which is also the return value. The function will panic if x is a negative number.
func LogN ¶
func LogN(z *inf.Dec, x *inf.Dec, n *inf.Dec, s inf.Scale) *inf.Dec
LogN computes the log of x with base n to the specified scale and stores the result in z, which is also the return value. The function will panic if x is a negative number or if n is a negative number.
func Mod ¶
func Mod(z, x, y *inf.Dec) *inf.Dec
Mod performs the modulo arithmatic x % y and stores the result in z, which is also the return value. It is valid for z to be nil, in which case it will be allocated internally. Mod will panic if the y is zero.
The modulo calculation is implemented using the algorithm:
x % y = x - (y * ⌊x / y⌋).
func NewDecFromFloat ¶
func NewDecFromFloat(f float64) *inf.Dec
NewDecFromFloat allocates and returns a new Dec set to the given float64 value. The function will panic if the float is NaN or ±Inf.
func NumDigits ¶
NumDigits returns the number of decimal digits that make up big.Int value. The function first attempts to look this digit count up in the digitsLookupTable. If the value is not there, it defaults to constructing a string value for the big.Int and using this to determine the number of digits. If a string value is constructed, it will be returned so it can be used again.
func Pow ¶
func Pow(z, x, y *inf.Dec, s inf.Scale) (*inf.Dec, error)
Pow computes (x^y) as e^(y ln x) to the specified scale and stores the result in z, which is also the return value. If y is not an integer and x is negative an error is returned. If x is zero and y is negative an error is returned.
func PowerOfTenDec ¶
func PowerOfTenDec(pow int) *inf.Dec
PowerOfTenDec returns an *inf.Dec with the value 10^pow. It should be treated as immutable.
Non-negative powers of 10 will have their value represented in their underlying big.Int with a scale of 0, while negative powers of 10 will have their value represented in their scale with a big.Int value of 1.
func PowerOfTenInt ¶
PowerOfTenInt returns a *big.Int with the value 10^pow. It should be treated as immutable.
func SetFromFloat ¶
func SetFromFloat(z *inf.Dec, f float64) *inf.Dec
SetFromFloat sets z to the given float64 value and returns z. The function will panic if the float is NaN or ±Inf.
func Sqrt ¶
func Sqrt(z, x *inf.Dec, s inf.Scale) *inf.Dec
Sqrt calculates the square root of x to the specified scale and stores the result in z, which is also the return value. The function will panic if x is a negative number.
The square root calculation is implemented using Newton's Method. We start with an initial estimate for sqrt(d), and then iterate:
x_{n+1} = 1/2 * ( x_n + (d / x_n) ).
Types ¶
This section is empty.