mathutil

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxTries = int32(100000)

Functions

func DivideInt64

func DivideInt64(dividend, divisor int64) (quotient, remainder int64)

DivideInt64 performs integer division, returning a quotient and remainder.

func DivmodInt64

func DivmodInt64(numerator, denominator int64) (quotient, remainder int64)

DivmodInt64 from https://stackoverflow.com/a/43945812

func FloorMostSignificant

func FloorMostSignificant(valOriginal int64) int64

FloorMostSignificant returns number with a single significant digit followed by zeros. The value returned is always lower than the supplied value.

func IntsToInt32s

func IntsToInt32s(ints []int) []int32

func IntsToUints

func IntsToUints(ints []int) []uint

func IsEven

func IsEven(i int) bool

func IsOdd

func IsOdd(i int) bool

func IsOverlapSortedInt

func IsOverlapSortedInt(x1, x2, y1, y2 int) bool

func IsOverlapSortedInt32

func IsOverlapSortedInt32(x1, x2, y1, y2 int32) bool

func IsOverlapSortedInt64

func IsOverlapSortedInt64(x1, x2, y1, y2 int64) bool

func IsOverlapUnsortedInt

func IsOverlapUnsortedInt(x1, x2, y1, y2 int) bool

func MinMaxInt32

func MinMaxInt32(vals ...int32) (int32, int32)

MinMaxInt32 returns min/max value given a slice of input values.

func MinMaxUint

func MinMaxUint(vals ...uint) (uint, uint)

MinMaxUint returns min/max value given a slice of input values.

func ModInt added in v0.0.4

func ModInt(a, b int) int

ModInt provides a Python-like Modulo function.

func ModInt64 added in v0.0.4

func ModInt64(a, b int64) int64

ModInt64 provides a Python-like Modulo function.

func PercentChangeToXoX

func PercentChangeToXoX(v float64) float64

PercentChangeToXoX converts a 1.0 == 100% based `float64` to a XoX percentage `float64`.

func PrettyTicks

func PrettyTicks(estimatedTickCount int, low, high int64) []int64

PrettyTicks returns a slice of integers that start lower and end higher than the supplied range. This is intended to be used for chart axis.

func PrettyTicksPercent

func PrettyTicksPercent(estimatedTickCount int, low, high float64, sigDigits uint8) []float64

func Round

func Round(x float64) float64

Round returns the nearest integer, rounding half away from zero. This function is available natively in Go 1.10

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN

This function is from the following gist by gdm85: https://gist.github.com/gdm85/44f648cc97bb3bf847f21c87e9d19b2d

func RoundMore

func RoundMore(val float64, roundOn float64, places int) (newVal float64)

Round is a rounding function for use before Go 1.11. The code was provided by David Vaini here: https://gist.github.com/DavidVaini/10308388

Types

type RangeFloat64

type RangeFloat64 struct {
	Min   float64
	Max   float64
	Cells int32
	// contains filtered or unexported fields
}

RangeFloat64 creates a range with a fixed set of cells and returns the cell for a certain value.

func (*RangeFloat64) CellIndexForValue

func (rng *RangeFloat64) CellIndexForValue(v float64) (int32, error)

CellIndexForValue returns a cell index for a requested value.

func (*RangeFloat64) CellMinMax

func (rng *RangeFloat64) CellMinMax(idx int32) (float64, float64, error)

type RangeInt64

type RangeInt64 struct {
	Min   int64
	Max   int64
	Cells int32
	// contains filtered or unexported fields
}

RangeFloat64 creates a range with a fixed set of cells and returns the cell for a certain value.

func (*RangeInt64) CellIndexForValue

func (rng *RangeInt64) CellIndexForValue(v int64) (int32, error)

CellIndexForValue returns a cell index for a requested value.

func (*RangeInt64) CellMinMax

func (rng *RangeInt64) CellMinMax(idx int32) (int64, int64, error)

func (*RangeInt64) CellRange

func (rng *RangeInt64) CellRange() (int64, error)

type SliceFloat64

type SliceFloat64 struct {
	Elements []float64
	Stats    SliceFloat64Stats
}

SliceFloat64 represets a slice of integers and provides functions on that slice.

func NewSliceFloat64

func NewSliceFloat64() SliceFloat64

NewSliceFloat64 creates and returns an empty SliceFloat64 struct.

func (*SliceFloat64) Append

func (sf64 *SliceFloat64) Append(num float64)

Append adds an element to the float64 slice.

func (*SliceFloat64) Average

func (sf64 *SliceFloat64) Average() (float64, error)

Average is an alias for Mean.

func (*SliceFloat64) BuildStats

func (sf64 *SliceFloat64) BuildStats() (SliceFloat64Stats, error)

BuildStats builds a stats struct for current float64 slice elements.

func (*SliceFloat64) Len

func (sf64 *SliceFloat64) Len() int

Len returns the number of items in the float64 slice.

func (*SliceFloat64) Max

func (sf64 *SliceFloat64) Max() (float64, error)

Max returns the maximum element value in the float64 slice.

func (*SliceFloat64) Mean

func (sf64 *SliceFloat64) Mean() (float64, error)

Mean returns the arithmetic mean of the float64 slice.

func (*SliceFloat64) Median

func (sf64 *SliceFloat64) Median() (float64, error)

Median returns the median or middle value of the sorted float64 slice.

func (*SliceFloat64) Min

func (sf64 *SliceFloat64) Min() (float64, error)

Min returns the minimum element value in the float64 slice.

func (*SliceFloat64) Sort

func (sf64 *SliceFloat64) Sort()

Sort sorts the elements in the float64 slice.

func (*SliceFloat64) Sum

func (sf64 *SliceFloat64) Sum() (float64, error)

Sum returns sum of all the elements in the float64 slice.

type SliceFloat64Stats

type SliceFloat64Stats struct {
	Len    int
	Max    float64
	Mean   float64
	Median float64
	Min    float64
	Sum    float64
}

SliceFloat64Stats represents a set of statistics for a set of float64s.

func NewSliceFloat64Stats

func NewSliceFloat64Stats() SliceFloat64Stats

NewSliceFloat64Stats returns a new initialized SliceFloat64Stats struct.

type SliceInt

type SliceInt struct {
	Elements []int
	Stats    SliceIntStats
}

SliceInt represets a slice of integers and provides functions on that slice.

func NewSliceInt

func NewSliceInt() SliceInt

NewSliceInt creates and returns an empty SliceInt struct.

func (*SliceInt) Append

func (sint *SliceInt) Append(num int)

Append adds an element to the integer slice.

func (*SliceInt) Average

func (sint *SliceInt) Average() (float64, error)

Average is an alias for Mean.

func (*SliceInt) BuildStats

func (sint *SliceInt) BuildStats() (SliceIntStats, error)

BuildStats builds a stats struct for current integer slice elements.

func (*SliceInt) Len

func (sint *SliceInt) Len() int

Len returns the number of items in the integer slice.

func (*SliceInt) Max

func (sint *SliceInt) Max() (int, error)

Max returns the maximum element value in the integer slice.

func (*SliceInt) Mean

func (sint *SliceInt) Mean() (float64, error)

Mean returns the arithmetic mean of the integer slice.

func (*SliceInt) Median

func (sint *SliceInt) Median() (int, error)

Median returns the median or middle value of the sorted integer slice.

func (*SliceInt) Min

func (sint *SliceInt) Min() (int, error)

Min returns the minimum element value in the integer slice.

func (*SliceInt) Sort

func (sint *SliceInt) Sort()

Sort sorts the elements in the integer slice.

func (*SliceInt) Sum

func (sint *SliceInt) Sum() (int, error)

Sum returns sum of all the elements in the integer slice.

type SliceIntStats

type SliceIntStats struct {
	Len    int
	Max    int
	Mean   float64
	Median int
	Min    int
	Sum    int
}

SliceIntStats represents a set of statistics for a set of integers.

func NewSliceIntStats

func NewSliceIntStats() SliceIntStats

NewSliceIntStats returns a new initialized SliceIntStats struct.

Jump to

Keyboard shortcuts

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