Documentation ¶
Overview ¶
Package mathutil contains generic helpers for common algorithms and mathematic operations.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolToNumber ¶
BoolToNumber returns 1 if cond is true and 0 otherwise.
Example ¶
package main import ( "fmt" "github.com/AdguardTeam/golibs/mathutil" ) func main() { fmt.Println(mathutil.BoolToNumber[int](true)) fmt.Println(mathutil.BoolToNumber[int](false)) type flag float64 fmt.Println(mathutil.BoolToNumber[flag](true)) fmt.Println(mathutil.BoolToNumber[flag](false)) }
Output: 1 0 1 0
func Max
deprecated
func Max[T constraints.Integer | ~string](x, y T) (res T)
Max returns the larger of x or y.
Deprecated: Use the built-in function max.
Example ¶
package main import ( "fmt" "github.com/AdguardTeam/golibs/mathutil" ) func main() { fmt.Println(mathutil.Max(1, 2)) fmt.Println(mathutil.Max(2, 1)) }
Output: 2 2
func Min
deprecated
func Min[T constraints.Integer | ~string](x, y T) (res T)
Min returns the smaller of x or y.
Deprecated: Use the built-in function min.
Example ¶
package main import ( "fmt" "github.com/AdguardTeam/golibs/mathutil" ) func main() { fmt.Println(mathutil.Min(1, 2)) fmt.Println(mathutil.Min(2, 1)) }
Output: 1 1
Types ¶
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
Number is a type constraint for all numbers.
Click to show internal directories.
Click to hide internal directories.