mathutil

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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.

func AngleToRadian

func AngleToRadian(angle float64) float64

AngleToRadian converts angle value to radian value.

func Average

func Average[T constraints.Integer | constraints.Float](numbers ...T) T

Average return average value of numbers.

func Cos

func Cos(radian float64, precision ...int) float64

Cos returns the cosine of the radian argument.

func Exponent

func Exponent(x, n int64) int64

Exponent calculate x^n.

func Factorial

func Factorial(x uint) uint

Factorial calculate x!.

func Fibonacci

func Fibonacci(first, second, n int) int

Fibonacci calculate fibonacci number before n.

func GCD

func GCD[T constraints.Integer](integers ...T) T

GCD return greatest common divisor (GCD) of integers.

func IsPrime

func IsPrime(n int) bool

IsPrime checks if number is prime number.

func LCM

func LCM[T constraints.Integer](integers ...T) T

LCM return Least Common Multiple (LCM) of integers.

func Log

func Log(n, base float64) float64

Log returns the logarithm of base n.

func Max

func Max[T constraints.Integer | constraints.Float](numbers ...T) T

Max return max value of numbers.

func MaxBy

func MaxBy[T any](slice []T, comparator func(T, T) bool) T

MaxBy return the maximum value of a slice using the given comparator function.

func Min

func Min[T constraints.Integer | constraints.Float](numbers ...T) T

Min return min value of numbers.

func MinBy

func MinBy[T any](slice []T, comparator func(T, T) bool) T

MinBy return the minimum value of a slice using the given comparator function.

func Percent

func Percent(val, total float64, n int) float64

Percent calculate the percentage of value to total.

func PointDistance

func PointDistance(x1, y1, x2, y2 float64) float64

PointDistance get two points distance.

func RadianToAngle

func RadianToAngle(radian float64) float64

RadianToAngle converts radian value to angle value.

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.

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.

func RoundToFloat

func RoundToFloat(x float64, n int) float64

RoundToFloat round up to n decimal places.

func RoundToString

func RoundToString(x float64, n int) string

RoundToString round up to n decimal places.

func Sin

func Sin(radian float64, precision ...int) float64

Sin returns the sine of the radian argument.

func Sum

func Sum[T constraints.Integer | constraints.Float](numbers ...T) T

Sum return sum of passed numbers.

func TruncRound

func TruncRound(x float64, n int) float64

TruncRound round off n decimal places.

Types

This section is empty.

Jump to

Keyboard shortcuts

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