Documentation
¶
Overview ¶
Package mathutil implements some functions for math calculation.
Index ¶
- func Abs[T constraints.Integer | constraints.Float](x T) T
- func AngleToRadian(angle float64) float64
- func Average[T constraints.Integer | constraints.Float](numbers ...T) T
- func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
- func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string
- func Cos(radian float64, precision ...int) float64
- func Div[T constraints.Float | constraints.Integer](x T, y T) float64
- func Exponent(x, n int64) int64
- func Factorial(x uint) uint
- func Fibonacci(first, second, n int) int
- func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
- func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string
- func GCD[T constraints.Integer](integers ...T) T
- func IsPrime(n int) bool
- func LCM[T constraints.Integer](integers ...T) T
- func Log(n, base float64) float64
- func Max[T constraints.Integer | constraints.Float](numbers ...T) T
- func MaxBy[T any](slice []T, comparator func(T, T) bool) T
- func Min[T constraints.Integer | constraints.Float](numbers ...T) T
- func MinBy[T any](slice []T, comparator func(T, T) bool) T
- func Percent(val, total float64, n int) float64
- func PointDistance(x1, y1, x2, y2 float64) float64
- func RadianToAngle(radian float64) float64
- func Range[T constraints.Integer | constraints.Float](start T, count int) []T
- func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T
- func RoundToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
- func RoundToString[T constraints.Float | constraints.Integer](x T, n int) string
- func Sin(radian float64, precision ...int) float64
- func Sum[T constraints.Integer | constraints.Float](numbers ...T) T
- func TruncRound[T constraints.Float | constraints.Integer](x T, n int) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[T constraints.Integer | constraints.Float](x T) T
Abs returns the absolute value of x. Play: https://go.dev/play/p/fsyBh1Os-1d
func AngleToRadian ¶
AngleToRadian converts angle value to radian value. Play: https://go.dev/play/p/CIvlICqrHql
func Average ¶
func Average[T constraints.Integer | constraints.Float](numbers ...T) T
Average return average value of numbers. Play: https://go.dev/play/p/Vv7LBwER-pz
func CeilToFloat ¶
func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
CeilToFloat round up to n decimal places. Play: https://go.dev/play/p/8hOeSADZPCo
func CeilToString ¶
func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string
CeilToString round up to n decimal places. Play: https://go.dev/play/p/wy5bYEyUKKG
func Cos ¶
Cos returns the cosine of the radian argument. Play: https://go.dev/play/p/Sm89LoIfvFq
func Div ¶
func Div[T constraints.Float | constraints.Integer](x T, y T) float64
Div returns the result of x divided by y. Play: https://go.dev/play/p/WLxDdGXXYat
func Exponent ¶
Exponent calculate x^n. Play: https://go.dev/play/p/uF3HGNPk8wr
func Factorial ¶
Factorial calculate x!. Play: https://go.dev/play/p/tt6LdOK67Nx
func Fibonacci ¶
Fibonacci calculate fibonacci number before n. Play: https://go.dev/play/p/IscseUNMuUc
func FloorToFloat ¶
func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
FloorToFloat round down to n decimal places. Play: https://go.dev/play/p/vbCBrQHZEED
func FloorToString ¶
func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string
FloorToString round down to n decimal places. Play: https://go.dev/play/p/Qk9KPd2IdDb
func GCD ¶
func GCD[T constraints.Integer](integers ...T) T
GCD return greatest common divisor (GCD) of integers. Play: https://go.dev/play/p/CiEceLSoAKB
func IsPrime ¶
IsPrime checks if number is prime number. Play: https://go.dev/play/p/Rdd8UTHZJ7u
func LCM ¶
func LCM[T constraints.Integer](integers ...T) T
LCM return Least Common Multiple (LCM) of integers. Play: https://go.dev/play/p/EjcZxfY7G_g
func Log ¶
Log returns the logarithm of base n. Play: https://go.dev/play/p/_d4bi8oyhat
func Max ¶
func Max[T constraints.Integer | constraints.Float](numbers ...T) T
Max return max value of numbers. Play: https://go.dev/play/p/cN8DHI0rTkH
func MaxBy ¶
MaxBy return the maximum value of a slice using the given comparator function. Play: https://go.dev/play/p/pbe2MT-7DV2
func Min ¶
func Min[T constraints.Integer | constraints.Float](numbers ...T) T
Min return min value of numbers. Play: https://go.dev/play/p/21BER_mlGUj
func MinBy ¶
MinBy return the minimum value of a slice using the given comparator function. Play: https://go.dev/play/p/XuJDKrDdglW
func Percent ¶
Percent calculate the percentage of value to total. Play: https://go.dev/play/p/s0NdFCtwuyd
func PointDistance ¶
PointDistance get two points distance. Play: https://go.dev/play/p/RrG4JIaziM8
func RadianToAngle ¶
RadianToAngle converts radian value to angle value. Play: https://go.dev/play/p/dQtmOTUOMgi
func Range ¶
func Range[T constraints.Integer | constraints.Float](start T, count int) []T
Range creates a slice of numbers from start with specified count, element step is 1. Play: https://go.dev/play/p/9ke2opxa8ZP
func RangeWithStep ¶
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T
RangeWithStep creates a slice of numbers from start to end with specified step. Play: https://go.dev/play/p/akLWz0EqOSM
func RoundToFloat ¶
func RoundToFloat[T constraints.Float | constraints.Integer](x T, n int) float64
RoundToFloat round off to n decimal places. Play: https://go.dev/play/p/ghyb528JRJL
func RoundToString ¶
func RoundToString[T constraints.Float | constraints.Integer](x T, n int) string
RoundToString round off to n decimal places. Play: https://go.dev/play/p/kZwpBRAcllO
func Sin ¶
Sin returns the sine of the radian argument. Play: https://go.dev/play/p/TWMQlMywDsP
func Sum ¶
func Sum[T constraints.Integer | constraints.Float](numbers ...T) T
Sum return sum of passed numbers. Play: https://go.dev/play/p/1To2ImAMJA7
func TruncRound ¶
func TruncRound[T constraints.Float | constraints.Integer](x T, n int) T
TruncRound round off n decimal places. Play: https://go.dev/play/p/aumarSHIGzP
Types ¶
This section is empty.