Documentation
¶
Overview ¶
Package simplemath implements math operations used by the algorithms in the coollex package.
Additionally, it includes simple, naive implementations of math operations that are designed to facilitate writing tests. These functions return an error upon numeric overflow: Add, Mul, etc. They are used exclusively in tests and not in the Cool-lex algorithm implementations.
Index ¶
- func Add(a, b uint) (uint, error)
- func BitEq32(a, b int32) int32
- func BitEq64(a, b int64) int64
- func Doz32(a, b int32) int32
- func Doz64(a, b int64) int64
- func DozB32(a, b int32) int32
- func DozB64(a, b int64) int64
- func Factorial(n uint) (uint, error)
- func Mul(a, b uint) (uint, error)
- func MulRange(n2, n1 uint) (r uint, err error)
- func NumComb(n, k uint) (uint, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Doz32 ¶
Doz32 implements the difference-or-zero function, in a branchless fashion. See `simplemath.DozB64` for details.
func Doz64 ¶
Doz64 implements the difference-or-zero function, in a branchless fashion. See `simplemath.DozB64` for details.
func DozB32 ¶
DozB32 implements the difference-or-zero function. See `simplemath.DozB64` for details.
func DozB64 ¶
DozB64 implements the difference-or-zero function. DozB64(a,b) is a - b if a >= b, and is 0 if a < b.
It is named "saturated subtraction" in The Coolest Way to Generate Combinations paper by Frank Ruskey and Aaron Williams, see 3.3. Implementation in Computer words, page 10.
See also: `simplemath.Doz64`.
func Factorial ¶
Factorial returns the factorial of n, or 1 for n=0. Error is reported if numeric overflow occurs.
func MulRange ¶
MulRange calculates the product of all integers within the inclusive interval [n1, n2] (or [n2, n1] if n2 < n1).
It returns the product if no numeric overflow occurs. Otherwise, it returns an error, and the partial product calculated before the overflow is stored in 'r'.
Types ¶
This section is empty.