mathg

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 2 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](n T) T

Abs returns the absolute int value of n.

func Average

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

Average returns the average of nums.

func Dim added in v2.0.2

func Dim[T constraints.Integer | constraints.Float](x, y T) T

Dim returns the maximum of x-y or 0.

func DivCeil added in v2.0.2

func DivCeil[T constraints.Integer | constraints.Float](x, y T) T

DivCeil returns the least integer value greater than or equal to x/y. If y == 0, the result will be 0.

func DivFloor added in v2.0.2

func DivFloor[T constraints.Integer | constraints.Float](x, y T) T

DivFloor returns the greatest integer value less than or equal to x/y. If y == 0, the result will be 0.

func DivRound added in v2.0.2

func DivRound[T constraints.Integer | constraints.Float](x, y T) T

DivRound returns the nearest integer, rounding half away from zero to x/y. If y == 0, the result will be 0.

func IsEven

func IsEven[T constraints.Integer](n T) bool

IsEven reports whether n is even number.

func IsNegative

func IsNegative[T constraints.Integer | constraints.Float](n T) bool

IsNegative returns:

 true if n <  0
false if n == 0
false if n >  0

func IsNonNegative

func IsNonNegative[T constraints.Integer | constraints.Float](n T) bool

IsNonNegative returns:

 true if n >  0
 true if n == 0
false if n <  0

func IsNonPositive

func IsNonPositive[T constraints.Integer | constraints.Float](n T) bool

IsNonPositive returns:

 true if n <  0
 true if n == 0
false if n >  0

func IsOdd

func IsOdd[T constraints.Integer](n T) bool

IsOdd reports whether n is odd number.

func IsPositive

func IsPositive[T constraints.Integer | constraints.Float](n T) bool

IsPositive returns:

 true if n >  0
false if n == 0
false if n <  0

func IsZero

func IsZero[T constraints.Integer | constraints.Float](n T) bool

IsZero returns:

 true if n == 0
false if n >  0
false if n <  0

func Max

func Max[T constraints.Ordered](nums ...T) T

Max returns the largest element in nums.

func MaxBy added in v2.0.2

func MaxBy[T any](slice []T, cmp func(a, b T) bool) T

MaxBy return the largest element in slice using the given cmp function.

func Min

func Min[T constraints.Ordered](nums ...T) T

Min returns the smallest element in nums.

func MinBy added in v2.0.2

func MinBy[T any](slice []T, cmp func(a, b T) bool) T

MinBy return the smallest element in slice using the given cmp function.

func Mod added in v2.0.2

func Mod[T constraints.Integer | constraints.Float](x, y T) T

Mod returns the remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x. If y == 0, the result will be 0.

func Pow added in v2.0.2

func Pow[T constraints.Integer | constraints.Float](x, y T) T

Pow returns x**y, the base-x exponential of y.

func Range

func Range[T constraints.Signed | constraints.Float](start, stop T, step ...T) []T

Range returns a slice, starting from start, and increments by step, and stops before stop. If start < stop, default step is 1, else default step is -1.

func Sign

func Sign[T constraints.Integer | constraints.Float](n T) int

Sign returns:

-1 if n <  0
 0 if n == 0
+1 if n >  0

func Sum

func Sum[T constraints.Ordered](nums ...T) T

Sum returns the sum of nums.

Types

This section is empty.

Jump to

Keyboard shortcuts

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