imath

package
v0.0.0-...-ea0ee21 Latest Latest
Warning

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

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

Documentation

Overview

Package imath contains tools for signed integer math. It largely corresponds with go's built in `math` library for float64s

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

Abs returns the absolute value of n

func Accumulate

func Accumulate(f func(int, int) int, a []int) []int

Accumulate returns a slice B where B[i] = Reduce(f, a[:i+1]).

func Clamp

func Clamp(n, low, high int) int

Clamp takes an int n, returns low if n < low, high if n > high, and n otherwise.

func Filter

func Filter(f func(int) bool, a []int) []int

Filter (f, a) returns a slice containing n for all n where f(n) == true

func Map

func Map(f func(int) int, a []int) []int

Map (f, a) returns a slice containing f(n) for every n in a

func Max

func Max(n int, a ...int) int

Max returns it's largest integer argument.

func Max2

func Max2(a, b int) int

Max2 returns the largest of two integer arguments.

func Min

func Min(n int, a ...int) int

Min returns it's smallest integer argument.

func Min2

func Min2(a, b int) int

Min2 returns the smallest of two integer arguments.

func Pow

func Pow(base, exp int) int

Pow is an efficent implementation of exponentiation by squaring.

func Product

func Product(a ...int) int

Product returns the product of it's arguments. Product() is 1.

func RandSign

func RandSign() int

RandSign returns -1 or 1 at random, using the default Source of math/rand. This is NOT crypto-safe, at all.

func Range

func Range(start, stop, step int) []int

Range returns the slice of integers in [start, stop) obtained by repeatedly adding step to start.

func Reduce

func Reduce(f func(int, int) int, start int, a ...int) int

func Sign

func Sign(n int) int

Sign returns the sign of the operand. The sign of zero is zero.

func Sum

func Sum(a ...int) int

Sum returns the sum of it's arguments. Sum() is 0

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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