math

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[N constraints.Number](n N) N

Abs returns the absolute value of a number.

func DivMod

func DivMod[N constraints.Integer](a, b N) (N, N)

DivMod returns the quotient and remainder of a division.

func Inf

func Inf[N constraints.Number]() N

Inf returns the maximum value of a number type.

func Max

func Max[V constraints.Ordered](seq iter.Seq[V]) V

Max returns the maximum value in the iterator.

Example
package main

import (
	"fmt"
	"slices"

	"github.com/elordeiro/goext/math"
)

func main() {
	seq := slices.Values([]int{1, 2, 3, 4, 5})
	fmt.Println(math.Max(seq))
}
Output:
5

func Min

func Min[V constraints.Ordered](seq iter.Seq[V]) V

Min returns the minimum value in the iterator.

Example
package main

import (
	"fmt"
	"slices"

	"github.com/elordeiro/goext/math"
)

func main() {
	seq := slices.Values([]int{1, 2, 3, 4, 5})
	fmt.Println(math.Min(seq))
}
Output:
1

func Product

func Product[V constraints.Integer](seq iter.Seq[V]) V

Product returns the product of all values in the iterator.

Example
package main

import (
	"fmt"
	"slices"

	"github.com/elordeiro/goext/math"
)

func main() {
	seq := slices.Values([]int{1, 2, 3, 4, 5})
	fmt.Println(math.Product(seq))
}
Output:
120

func Sum

func Sum[V constraints.Ordered](seq iter.Seq[V]) V

Sum returns the sum of all values in the iterator.

Example
package main

import (
	"fmt"
	"slices"

	"github.com/elordeiro/goext/math"
)

func main() {
	seq := slices.Values([]int{1, 2, 3, 4, 5})
	fmt.Println(math.Sum(seq))
}
Output:
15

Types

This section is empty.

Jump to

Keyboard shortcuts

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