mathutil

package
v12.126.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 1 Imported by: 6

Documentation

Overview

Package mathutil provides some additional math methods

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[N NumericNeg](val N) N

Abs returns absolute value

Example
fmt.Println(Abs(10))
fmt.Println(Abs(-10))
Output:

10
10

func Between

func Between[N Numeric](val, min, max N) N

Between returns value between min and max values

Example
fmt.Println(Between(10, 1, 5))
fmt.Println(Between(-3, 1, 5))
fmt.Println(Between(4, 1, 5))
Output:

5
1
4

func Max

func Max[N Numeric](val1, val2 N) N

Max returns a greater value

Example
fmt.Println(Max(1, 10))
fmt.Println(Max(3, -3))
Output:

10
3

func Min

func Min[N Numeric](val1, val2 N) N

Min returns a smaller value

Example
fmt.Println(Min(1, 10))
fmt.Println(Min(3, -3))
Output:

1
-3

func Perc added in v12.98.0

func Perc[N Numeric](val1, val2 N) float64

Perc calculates percentage

Example
fmt.Printf("%g%%\n", Perc(180, 600))
Output:

30%

func Round

func Round(v float64, p int) float64

Round returns rounded value

Example
fmt.Println(Round(3.14159, 2))
Output:

3.14

Types

type Integer added in v12.125.0

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type Numeric added in v12.72.0

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64
}

type NumericNeg added in v12.72.0

type NumericNeg interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64
}

Jump to

Keyboard shortcuts

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