Documentation ¶
Overview ¶
Package mathutil provides utilities supplementing the standard 'math' and 'math/rand' packages.
Release history and compatibility issues ¶
2018-10-21 Added BinaryLog
2018-04-25: New functions for determinig Max/Min of nullable values. Ex:
func MaxPtr(a, b *int) *int { func MinPtr(a, b *int) *int { func MaxBytePtr(a, b *byte) *byte { func MinBytePtr(a, b *byte) *byte { ...
2017-10-14: New variadic functions for Max/Min. Ex:
func MaxVal(val int, vals ...int) int { func MinVal(val int, vals ...int) int { func MaxByteVal(val byte, vals ...byte) byte { func MinByteVal(val byte, vals ...byte) byte { ...
2016-10-10: New functions QuadPolyDiscriminant and QuadPolyFactors.
2013-12-13: The following functions have been REMOVED
func Uint64ToBigInt(n uint64) *big.Int func Uint64FromBigInt(n *big.Int) (uint64, bool)
2013-05-13: The following functions are now DEPRECATED
func Uint64ToBigInt(n uint64) *big.Int func Uint64FromBigInt(n *big.Int) (uint64, bool)
These functions will be REMOVED with Go release 1.1+1.
2013-01-21: The following functions have been REMOVED
func MaxInt() int func MinInt() int func MaxUint() uint func UintPtrBits() int
They are now replaced by untyped constants
MaxInt MinInt MaxUint UintPtrBits
Additionally one more untyped constant was added
IntBits
This change breaks any existing code depending on the above removed functions. They should have not been published in the first place, that was unfortunate. Instead, defining such architecture and/or implementation specific integer limits and bit widths as untyped constants improves performance and allows for static dead code elimination if it depends on these values. Thanks to minux for pointing it out in the mail list (https://groups.google.com/d/msg/golang-nuts/tlPpLW6aJw8/NT3mpToH-a4J).
2012-12-12: The following functions will be DEPRECATED with Go release 1.0.3+1 and REMOVED with Go release 1.0.3+2, b/c of http://code.google.com/p/go/source/detail?r=954a79ee3ea8
func Uint64ToBigInt(n uint64) *big.Int func Uint64FromBigInt(n *big.Int) (uint64, bool)
Index ¶
- Constants
- Variables
- func AddUint128_64(a, b uint64) (hi uint64, lo uint64)
- func BinaryLog(n *big.Int, mantissaBits int) (characteristic int, mantissa *big.Int)
- func BitLen(n int) int
- func BitLenByte(n byte) int
- func BitLenUint(n uint) int
- func BitLenUint16(n uint16) int
- func BitLenUint32(n uint32) int
- func BitLenUint64(n uint64) int
- func BitLenUintptr(n uintptr) int
- func Clamp(v, lo, hi int) int
- func ClampByte(v, lo, hi byte) byte
- func ClampInt16(v, lo, hi int16) int16
- func ClampInt32(v, lo, hi int32) int32
- func ClampInt64(v, lo, hi int64) int64
- func ClampInt8(v, lo, hi int8) int8
- func ClampUint16(v, lo, hi uint16) uint16
- func ClampUint32(v, lo, hi uint32) uint32
- func ClampUint64(v, lo, hi uint64) uint64
- func Envelope(x float64, points []float64, approximation Approximation) float64
- func GCDByte(a, b byte) byte
- func GCDUint16(a, b uint16) uint16
- func GCDUint32(a, b uint32) uint32
- func GCDUint64(a, b uint64) uint64
- func ISqrt(n uint32) (x uint32)
- func IsPrime(n uint32) bool
- func IsPrimeUint16(n uint16) bool
- func IsPrimeUint64(n uint64) bool
- func Log2Byte(n byte) int
- func Log2Uint16(n uint16) int
- func Log2Uint32(n uint32) int
- func Log2Uint64(n uint64) int
- func Max(a, b int) int
- func MaxByte(a, b byte) byte
- func MaxBytePtr(a, b *byte) *byte
- func MaxByteVal(val byte, vals ...byte) byte
- func MaxInt16(a, b int16) int16
- func MaxInt16Ptr(a, b *int16) *int16
- func MaxInt16Val(val int16, vals ...int16) int16
- func MaxInt32(a, b int32) int32
- func MaxInt32Ptr(a, b *int32) *int32
- func MaxInt32Val(val int32, vals ...int32) int32
- func MaxInt64(a, b int64) int64
- func MaxInt64Ptr(a, b *int64) *int64
- func MaxInt64Val(val int64, vals ...int64) int64
- func MaxInt8(a, b int8) int8
- func MaxInt8Ptr(a, b *int8) *int8
- func MaxInt8Val(val int8, vals ...int8) int8
- func MaxPtr(a, b *int) *int
- func MaxUint16(a, b uint16) uint16
- func MaxUint16Ptr(a, b *uint16) *uint16
- func MaxUint16Val(val uint16, vals ...uint16) uint16
- func MaxUint32(a, b uint32) uint32
- func MaxUint32Ptr(a, b *uint32) *uint32
- func MaxUint32Val(val uint32, vals ...uint32) uint32
- func MaxUint64(a, b uint64) uint64
- func MaxUint64Ptr(a, b *uint64) *uint64
- func MaxUint64Val(val uint64, vals ...uint64) uint64
- func MaxVal(val int, vals ...int) int
- func Min(a, b int) int
- func MinByte(a, b byte) byte
- func MinBytePtr(a, b *byte) *byte
- func MinByteVal(val byte, vals ...byte) byte
- func MinInt16(a, b int16) int16
- func MinInt16Ptr(a, b *int16) *int16
- func MinInt16Val(val int16, vals ...int16) int16
- func MinInt32(a, b int32) int32
- func MinInt32Ptr(a, b *int32) *int32
- func MinInt32Val(val int32, vals ...int32) int32
- func MinInt64(a, b int64) int64
- func MinInt64Ptr(a, b *int64) *int64
- func MinInt64Val(val int64, vals ...int64) int64
- func MinInt8(a, b int8) int8
- func MinInt8Ptr(a, b *int8) *int8
- func MinInt8Val(val int8, vals ...int8) int8
- func MinPtr(a, b *int) *int
- func MinUint16(a, b uint16) uint16
- func MinUint16Ptr(a, b *uint16) *uint16
- func MinUint16Val(val uint16, vals ...uint16) uint16
- func MinUint32(a, b uint32) uint32
- func MinUint32Ptr(a, b *uint32) *uint32
- func MinUint32Val(val uint32, vals ...uint32) uint32
- func MinUint64(a, b uint64) uint64
- func MinUint64Ptr(a, b *uint64) *uint64
- func MinUint64Val(val uint64, vals ...uint64) uint64
- func MinVal(val int, vals ...int) int
- func ModPowBigInt(b, e, m *big.Int) (r *big.Int)
- func ModPowByte(b, e, m byte) byte
- func ModPowUint16(b, e, m uint16) uint16
- func ModPowUint32(b, e, m uint32) uint32
- func ModPowUint64(b, e, m uint64) (r uint64)
- func MulUint128_64(a, b uint64) (hi, lo uint64)
- func NextPrime(n uint32) (p uint32, ok bool)
- func NextPrimeUint16(n uint16) (p uint16, ok bool)
- func NextPrimeUint64(n uint64) (p uint64, ok bool)
- func PermutationFirst(data sort.Interface)
- func PermutationNext(data sort.Interface) bool
- func PopCount(n int) int
- func PopCountBigInt(n *big.Int) (r int)
- func PopCountByte(n byte) int
- func PopCountUint(n uint) int
- func PopCountUint16(n uint16) int
- func PopCountUint32(n uint32) int
- func PopCountUint64(n uint64) int
- func PopCountUintptr(n uintptr) int
- func PowerizeBigInt(b, n *big.Int) (e uint32, p *big.Int)
- func PowerizeUint32BigInt(b uint32, n *big.Int) (e uint32, p *big.Int)
- func PrimorialProductsUint32(lo, hi, max uint32) (r []uint32)
- func ProbablyPrimeBigInt(n, a *big.Int) bool
- func ProbablyPrimeBigInt_32(n *big.Int, a uint32) bool
- func ProbablyPrimeUint32(n, a uint32) bool
- func ProbablyPrimeUint64_32(n uint64, a uint32) bool
- func QCmpUint32(a, b, c, d uint32) int
- func QScaleUint32(b, c, d uint32) (a uint64)
- func QuadPolyDiscriminant(a, b, c int) (ds, d int, _ error)
- func QuadPolyDiscriminantBig(a, b, c *big.Int) (ds, d *big.Int)
- func SqrtBig(n *big.Int) (x *big.Int)
- func SqrtUint64(n uint64) (x uint64)
- func ToBase(n *big.Int, b int) []int
- func UClamp(v, lo, hi uint) uint
- func UMax(a, b uint) uint
- func UMaxPtr(a, b *uint) *uint
- func UMaxVal(val uint, vals ...uint) uint
- func UMin(a, b uint) uint
- func UMinPtr(a, b *uint) *uint
- func UMinVal(val uint, vals ...uint) uint
- func UintptrBits() int
- type Approximation
- type FC32
- type FCBig
- type FactorTerm
- type FactorTerms
- type Int128
- func (x Int128) Add(y Int128) (r Int128, cy bool)
- func (x Int128) BigInt() *big.Int
- func (x Int128) Cmp(y Int128) int
- func (x Int128) Neg() (r Int128, ok bool)
- func (x *Int128) SetBigInt(y *big.Int) (r Int128, err error)
- func (x *Int128) SetInt64(y int64) (r Int128)
- func (x *Int128) SetUint64(y uint64) (r Int128)
- func (x Int128) Sign() int
- func (x Int128) String() string
- type PolyFactor
- type PolyFactorBig
Examples ¶
Constants ¶
const ( MaxInt = 1<<(IntBits-1) - 1 MinInt = -MaxInt - 1 MaxUint = 1<<IntBits - 1 IntBits = 1 << (^uint(0)>>32&1 + ^uint(0)>>16&1 + ^uint(0)>>8&1 + 3) UintPtrBits = 1 << (^uintptr(0)>>32&1 + ^uintptr(0)>>16&1 + ^uintptr(0)>>8&1 + 3) )
Architecture and/or implementation specific integer limits and bit widths.
Variables ¶
var ( // The maximun Int128 value. MaxInt128 *big.Int // The minimun Int128 value. MinInt128 *big.Int )
Functions ¶
func AddUint128_64 ¶
AddUint128_64 returns the uint128 sum of uint64 a and b.
func BinaryLog ¶
BinaryLog computes the binary logarithm of n. The result consists of a characteristic and a mantissa having precision mantissaBits. The value of the binary logarithm is
characteristic + mantissa*(2^-mantissaBits)
BinaryLog panics for n <= 0 or mantissaBits < 0.
Example ¶
const mantBits = 257 x, _ := big.NewInt(0).SetString("89940344608680314083397671686667731393131665861770496634981932531495305005604", 10) c, m := BinaryLog(x, mantBits) f := big.NewFloat(0).SetPrec(mantBits).SetInt(m) f = f.SetMantExp(f, -mantBits) f.Add(f, big.NewFloat(float64(c))) f.Quo(f, big.NewFloat(4)) fmt.Printf("%.75f", f)
Output: 63.908875905794799149011030723455843229394283193466612998787786375106246936971
func BitLenByte ¶
BitLenByte returns the bit width of the non zero part of n.
func BitLenUint ¶
BitLenUint returns the bit width of the non zero part of n.
func BitLenUint16 ¶
BitLenUint16 returns the bit width of the non zero part of n.
func BitLenUint32 ¶
BitLenUint32 returns the bit width of the non zero part of n.
func BitLenUint64 ¶
BitLenUint64 returns the bit width of the non zero part of n.
func BitLenUintptr ¶
BitLenUintptr returns the bit width of the non zero part of n.
func ClampInt16 ¶
ClampInt16 returns a value restricted between lo and hi.
func ClampInt32 ¶
ClampInt32 returns a value restricted between lo and hi.
func ClampInt64 ¶
ClampInt64 returns a value restricted between lo and hi.
func ClampUint16 ¶
ClampUint16 returns a value restricted between lo and hi.
func ClampUint32 ¶
ClampUint32 returns a value restricted between lo and hi.
func ClampUint64 ¶
ClampUint64 returns a value restricted between lo and hi.
func Envelope ¶
func Envelope(x float64, points []float64, approximation Approximation) float64
Envelope is an utility for defining simple curves using a small (usually) set of data points. Envelope returns a value defined by x, points and approximation. The value of x must be in [0,1) otherwise the result is undefined or the function may panic. Points are interpreted as dividing the [0,1) interval in len(points)-1 sections, so len(points) must be > 1 or the function may panic. According to the left and right points closing/adjacent to the section the resulting value is interpolated using the chosen approximation method. Unsupported values of approximation are silently interpreted as 'Linear'.
func GCDByte ¶
GCDByte returns the greatest common divisor of a and b. Based on: http://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations
func IsPrime ¶
IsPrime returns true if n is prime. Typical run time is about 100 ns.
TODO rename to IsPrimeUint32
func IsPrimeUint16 ¶
IsPrimeUint16 returns true if n is prime. Typical run time is few ns.
func IsPrimeUint64 ¶
IsPrimeUint64 returns true if n is prime. Typical run time is few tens of µs.
SPRP bases: http://miller-rabin.appspot.com
func Log2Byte ¶
Log2Byte returns log base 2 of n. It's the same as index of the highest bit set in n. For n == 0 -1 is returned.
func Log2Uint16 ¶
Log2Uint16 returns log base 2 of n. It's the same as index of the highest bit set in n. For n == 0 -1 is returned.
func Log2Uint32 ¶
Log2Uint32 returns log base 2 of n. It's the same as index of the highest bit set in n. For n == 0 -1 is returned.
func Log2Uint64 ¶
Log2Uint64 returns log base 2 of n. It's the same as index of the highest bit set in n. For n == 0 -1 is returned.
func MaxBytePtr ¶
MaxBytePtr returns a pointer to the larger of a and b, or nil.
func MaxByteVal ¶
MaxByteVal returns the largest argument passed.
func MaxInt16Ptr ¶
MaxInt16Ptr returns a pointer to the larger of a and b, or nil.
func MaxInt16Val ¶
MaxInt16Val returns the largest argument passed.
func MaxInt32Ptr ¶
MaxInt32Ptr returns a pointer to the larger of a and b, or nil.
func MaxInt32Val ¶
MaxInt32Val returns the largest argument passed.
func MaxInt64Ptr ¶
MaxInt64Ptr returns a pointer to the larger of a and b, or nil.
func MaxInt64Val ¶
MaxInt64Val returns the largest argument passed.
func MaxInt8Ptr ¶
MaxInt8Ptr returns a pointer to the larger of a and b, or nil.
func MaxInt8Val ¶
MaxInt8Val returns the largest argument passed.
func MaxUint16Ptr ¶
MaxUint16Ptr returns a pointer to the larger of a and b, or nil.
func MaxUint16Val ¶
MaxUint16Val returns the largest argument passed.
func MaxUint32Ptr ¶
MaxUint32Ptr returns a pointer to the larger of a and b, or nil.
func MaxUint32Val ¶
MaxUint32Val returns the largest argument passed.
func MaxUint64Ptr ¶
MaxUint64Ptr returns a pointer to the larger of a and b, or nil.
func MaxUint64Val ¶
MaxUint64Val returns the largest argument passed.
func MinBytePtr ¶
MinBytePtr returns a pointer to the smaller of a and b, or nil.
func MinByteVal ¶
MinByteVal returns the smallest argument passed.
func MinInt16Ptr ¶
MinInt16Ptr returns a pointer to the smaller of a and b, or nil.
func MinInt16Val ¶
MinInt16Val returns the smallest argument passed.
func MinInt32Ptr ¶
MinInt32Ptr returns a pointer to the smaller of a and b, or nil.
func MinInt32Val ¶
MinInt32Val returns the smallest argument passed.
func MinInt64Ptr ¶
MinInt64Ptr returns a pointer to the smaller of a and b, or nil.
func MinInt64Val ¶
MinInt64Val returns the smallest argument passed.
func MinInt8Ptr ¶
MinInt8Ptr returns a pointer to the smaller of a and b, or nil.
func MinInt8Val ¶
MinInt8Val returns the smallest argument passed.
func MinUint16Ptr ¶
MinUint16Ptr returns a pointer to the smaller of a and b, or nil.
func MinUint16Val ¶
MinUint16Val returns the smallest argument passed.
func MinUint32Ptr ¶
MinUint32Ptr returns a pointer to the smaller of a and b, or nil.
func MinUint32Val ¶
MinUint32Val returns the smallest argument passed.
func MinUint64Ptr ¶
MinUint64Ptr returns a pointer to the smaller of a and b, or nil.
func MinUint64Val ¶
MinUint64Val returns the smallest argument passed.
func ModPowBigInt ¶
ModPowBigInt computes (b^e)%m. Returns nil for e < 0. It panics for m == 0 || b == e == 0.
func ModPowByte ¶
ModPowByte computes (b^e)%m. It panics for m == 0 || b == e == 0.
See also: http://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
func ModPowUint16 ¶
ModPowUint16 computes (b^e)%m. It panics for m == 0 || b == e == 0.
func ModPowUint32 ¶
ModPowUint32 computes (b^e)%m. It panics for m == 0 || b == e == 0.
func ModPowUint64 ¶
ModPowUint64 computes (b^e)%m. It panics for m == 0 || b == e == 0.
func MulUint128_64 ¶
MulUint128_64 returns the uint128 bit product of uint64 a and b.
func NextPrime ¶
NextPrime returns first prime > n and true if successful or an undefined value and false if there is no next prime in the uint32 limits. Typical run time is about 2 µs.
TODO rename to NextPrimeUint32
func NextPrimeUint16 ¶
NextPrimeUint16 returns first prime > n and true if successful or an undefined value and false if there is no next prime in the uint16 limits. Typical run time is few ns.
func NextPrimeUint64 ¶
NextPrimeUint64 returns first prime > n and true if successful or an undefined value and false if there is no next prime in the uint64 limits. Typical run time is in hundreds of µs.
func PermutationFirst ¶
PermutationFirst generates the first permutation of data.
func PermutationNext ¶
PermutationNext generates the next permutation of data if possible and return true. Return false if there is no more permutation left. Based on the algorithm described here: http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order
func PopCountBigInt ¶
PopCountBigInt returns population count of |n| (number of bits set in |n|).
func PopCountByte ¶
PopCountByte returns population count of n (number of bits set in n).
func PopCountUint ¶
PopCountUint returns population count of n (number of bits set in n).
func PopCountUint16 ¶
PopCountUint16 returns population count of n (number of bits set in n).
func PopCountUint32 ¶
PopCountUint32 returns population count of n (number of bits set in n).
func PopCountUint64 ¶
PopCountUint64 returns population count of n (number of bits set in n).
func PopCountUintptr ¶
PopCountUintptr returns population count of n (number of bits set in n).
func PowerizeBigInt ¶
PowerizeBigInt returns (e, p) such that e is the smallest number for which p == b^e is greater or equal n. For n < 0 or b < 2 (0, nil) is returned.
NOTE: Run time for large values of n (above about 2^1e6 ~= 1e300000) can be significant and/or unacceptabe. For any smaller values of n the function typically performs in sub second time. For "small" values of n (cca bellow 2^1e3 ~= 1e300) the same can be easily below 10 µs.
A special (and trivial) case of b == 2 is handled separately and performs much faster.
func PowerizeUint32BigInt ¶
PowerizeUint32BigInt returns (e, p) such that e is the smallest number for which p == b^e is greater or equal n. For n < 0 or b < 2 (0, nil) is returned.
More info: see PowerizeBigInt.
func PrimorialProductsUint32 ¶
PrimorialProductsUint32 returns a slice of numbers in [lo, hi] which are a product of max 'max' primorials. The slice is not sorted.
See also: http://en.wikipedia.org/wiki/Primorial
func ProbablyPrimeBigInt ¶
ProbablyPrimeBigInt returns true if n is prime or n is a pseudoprime to base a. It implements the Miller-Rabin primality test for one specific value of 'a' and k == 1. See also ProbablyPrimeUint32.
func ProbablyPrimeBigInt_32 ¶
ProbablyPrimeBigInt_32 returns true if n is prime or n is a pseudoprime to base a. It implements the Miller-Rabin primality test for one specific value of 'a' and k == 1. See also ProbablyPrimeUint32.
func ProbablyPrimeUint32 ¶
ProbablyPrimeUint32 returns true if n is prime or n is a pseudoprime to base a. It implements the Miller-Rabin primality test for one specific value of 'a' and k == 1.
Wrt pseudocode shown at http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time
Input: n > 3, an odd integer to be tested for primality; Input: k, a parameter that determines the accuracy of the test Output: composite if n is composite, otherwise probably prime write n − 1 as 2^s·d with d odd by factoring powers of 2 from n − 1 LOOP: repeat k times: pick a random integer a in the range [2, n − 2] x ← a^d mod n if x = 1 or x = n − 1 then do next LOOP for r = 1 .. s − 1 x ← x^2 mod n if x = 1 then return composite if x = n − 1 then do next LOOP return composite return probably prime
... this function behaves like passing 1 for 'k' and additionally a fixed/non-random 'a'. Otherwise it's the same algorithm.
See also: http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html
func ProbablyPrimeUint64_32 ¶
ProbablyPrimeUint64_32 returns true if n is prime or n is a pseudoprime to base a. It implements the Miller-Rabin primality test for one specific value of 'a' and k == 1. See also ProbablyPrimeUint32.
func QCmpUint32 ¶
QCmpUint32 compares a/b and c/d and returns:
-1 if a/b < c/d 0 if a/b == c/d +1 if a/b > c/d
func QScaleUint32 ¶
QScaleUint32 returns a such that a/b >= c/d.
func QuadPolyDiscriminant ¶
QuadPolyDiscriminant returns the discriminant of a quadratic polynomial in one variable of the form a*x^2+b*x+c with integer coefficients a, b, c, or an error on overflow.
ds is the square of the discriminant. If |ds| is a square number, d is set to sqrt(|ds|), otherwise d is < 0.
func QuadPolyDiscriminantBig ¶
QuadPolyDiscriminantBig returns the discriminant of a quadratic polynomial in one variable of the form a*x^2+b*x+c with integer coefficients a, b, c.
ds is the square of the discriminant. If |ds| is a square number, d is set to sqrt(|ds|), otherwise d is nil.
func SqrtUint64 ¶
SqrtUint64 returns floor(sqrt(n)). Typical run time is about 0.5 µs.
func ToBase ¶
ToBase produces n in base b. For example
ToBase(2047, 22) -> [1, 5, 4] 1 * 22^0 1 5 * 22^1 110 4 * 22^2 1936 ---- 2047
ToBase panics for bases < 2.
func UintptrBits ¶
func UintptrBits() int
UintptrBits returns the bit width of an uintptr at the executing machine.
Types ¶
type Approximation ¶
type Approximation int
Approximation type determines approximation methods used by e.g. Envelope.
const ( Linear Approximation // As named Sinusoidal // Smooth for all derivations )
Specific approximation method tags
type FC32 ¶
type FC32 struct {
// contains filtered or unexported fields
}
FC32 is a full cycle PRNG covering the 32 bit signed integer range. In contrast to full cycle generators shown at e.g. http://en.wikipedia.org/wiki/Full_cycle, this code doesn't produce values at constant delta (mod cycle length). The 32 bit limit is per this implementation, the algorithm used has no intrinsic limit on the cycle size. Properties include:
- Adjustable limits on creation (hi, lo).
- Positionable/randomly accessible (Pos, Seek).
- Repeatable (deterministic).
- Can run forward or backward (Next, Prev).
- For a billion numbers cycle the Next/Prev PRN can be produced in cca 100-150ns. That's like 5-10 times slower compared to PRNs generated using the (non FC) rand package.
func NewFC32 ¶
NewFC32 returns a newly created FC32 adjusted for the closed interval [lo, hi] or an Error if any. If hq == true then trade some generation time for improved (pseudo)randomness.
func (*FC32) Cycle ¶
Cycle reports the length of the inner FCPRNG cycle. Cycle is atmost the double (HQ: triple) of the generator period (hi - lo + 1).
type FCBig ¶
type FCBig struct {
// contains filtered or unexported fields
}
FCBig is a full cycle PRNG covering ranges outside of the int32 limits. For more info see the FC32 docs. Next/Prev PRN on a 1e15 cycle can be produced in about 2 µsec.
func NewFCBig ¶
NewFCBig returns a newly created FCBig adjusted for the closed interval [lo, hi] or an Error if any. If hq == true then trade some generation time for improved (pseudo)randomness.
func (*FCBig) Cycle ¶
Cycle reports the length of the inner FCPRNG cycle. Cycle is atmost the double (HQ: triple) of the generator period (hi - lo + 1).
type FactorTerm ¶
FactorTerm is one term of an integer factorization.
type FactorTerms ¶
type FactorTerms []FactorTerm
FactorTerms represent a factorization of an integer
func FactorInt ¶
func FactorInt(n uint32) (f FactorTerms)
FactorInt returns prime factorization of n > 1 or nil otherwise. Resulting factors are ordered by Prime. Typical run time is few µs.
type Int128 ¶
Int128 is an 128 bit integer.
type PolyFactor ¶
type PolyFactor struct {
P, Q int
}
PolyFactor describes an irreducible factor of a polynomial in one variable with integer coefficients P, Q of the form P*x+Q.
func QuadPolyFactors ¶
func QuadPolyFactors(a, b, c int) (content int, primitivePart []PolyFactor, _ error)
QuadPolyFactors returns the content and the irreducible factors of the primitive part of a quadratic polynomial in one variable with integer coefficients a, b, c of the form a*x^2+b*x+c in integers, or an error on overflow.
If the factorization in integers does not exists, the return value is (0, nil, nil).
type PolyFactorBig ¶
PolyFactorBig describes an irreducible factor of a polynomial in one variable with integer coefficients P, Q of the form P*x+Q.
func QuadPolyFactorsBig ¶
func QuadPolyFactorsBig(a, b, c *big.Int) (content *big.Int, primitivePart []PolyFactorBig)
QuadPolyFactorsBig returns the content and the irreducible factors of the primitive part of a quadratic polynomial in one variable with integer coefficients a, b, c of the form a*x^2+b*x+c in integers.
If the factorization in integers does not exists, the return value is (nil, nil).