mathutil

package
v13.21.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: Apache-2.0 Imports: 1 Imported by: 17

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
Output:

10
10

func B added in v13.10.1

func B[N Numeric](cond bool, positive, negative N) N

B is shorthand for choosing value by condition

Example
Output:

0
1000

func Between

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

Between returns value between min and max values

Example
Output:

5
1
4

func FromPerc added in v13.5.1

func FromPerc(perc float64, total float64) float64

FromPerc calculates value from percentage

Example
Output:

429

func IsFloat added in v13.5.0

func IsFloat(s string) bool

IsFloat returns true if given string contains float symbols.

Note that this method does not validate the given value.

Example
Output:

false
true
true

func IsInt added in v13.5.0

func IsInt(s string) bool

IsInt returns true if given string contains int symbols.

Note that this method does not validate the given value.

Example
Output:

false
true
true

func IsNumber added in v13.5.0

func IsNumber(s string) bool

IsNumber returns true if given string contains number symbols (int or float).

Note that this method does not validate the given value.

Example
Output:

false
true
true

func Max

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

Max returns a greater value

Example
Output:

10
3

func Min

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

Min returns a smaller value

Example
Output:

1
-3

func Perc

func Perc[N Numeric](current, total N) float64

Perc calculates percentage

Example
Output:

30%

func Round

func Round(v float64, p int) float64

Round returns rounded value

Example
Output:

3.14

Types

type Float added in v13.13.0

type Float interface {
	~float32 | ~float64
}

type Integer

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

type Numeric

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

type NumericNeg

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