mathutil

package
v0.0.0-...-3dbf936 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package mathutil implements some functions for math calculation.

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. Play: https://go.dev/play/p/fsyBh1Os-1d

func AngleToRadian

func AngleToRadian(angle float64) float64

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

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

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

func Exponent(x, n int64) int64

Exponent calculate x^n. Play: https://go.dev/play/p/uF3HGNPk8wr

func Factorial

func Factorial(x uint) uint

Factorial calculate x!. Play: https://go.dev/play/p/tt6LdOK67Nx

func Fibonacci

func Fibonacci(first, second, n int) int

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

func IsPrime(n int) bool

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

func Log(n, base float64) float64

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

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

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. Play: https://go.dev/play/p/XuJDKrDdglW

func Percent

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

Percent calculate the percentage of value to total. Play: https://go.dev/play/p/s0NdFCtwuyd

func PointDistance

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

PointDistance get two points distance. Play: https://go.dev/play/p/RrG4JIaziM8

func RadianToAngle

func RadianToAngle(radian float64) float64

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

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

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.

Jump to

Keyboard shortcuts

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