simplemath

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package simplemath offers simple/naive implementations of math operations for the purposes of aiding in writing auto tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(a, b uint) (uint, error)

Add returns the sum of a and b if no numeric overflow occurs, or an error otherwise.

func Factorial

func Factorial(n uint) (uint, error)

Factorial returns the factorial of n, or 1 for n=0. Error is reported if numeric overflow occurs.

func Mul

func Mul(a, b uint) (uint, error)

Mul returns the product of a and b, or an error if numeric overflow occurs.

func MulRange

func MulRange(n2, n1 uint) (r uint, err error)

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'.

func NumComb

func NumComb(n, k uint) (uint, error)

NumComb calculates the number of combinations for the specified k and n.

n: number of elements to combine; n>=k must hold. k: number of elements in a combination.

Error is reported if numeric overflow occurs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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