mathx

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Additional functions for math calculation that are missing in the standard library.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg added in v0.3.5

func Avg(values ...float64) float64

Returns the average value of the given values.

Example
package main

import (
	"fmt"

	"github.com/ayonli/goext/mathx"
)

func main() {
	fmt.Println(mathx.Avg(1))
	fmt.Println(mathx.Avg(1, 2))
	fmt.Println(mathx.Avg(1, 2, 3))
}
Output:
1
1.5
2

func Max

func Max(first float64, rest ...float64) float64

Returns the maximal value from the given values.

Example
package main

import (
	"fmt"

	"github.com/ayonli/goext/mathx"
)

func main() {
	fmt.Println(mathx.Max(1))
	fmt.Println(mathx.Max(1, 2))
	fmt.Println(mathx.Max(1, 2, 0.5))
}
Output:
1
2
2

func Min

func Min(first float64, rest ...float64) float64

Returns the minimal value from the given values.

Example
package main

import (
	"fmt"

	"github.com/ayonli/goext/mathx"
)

func main() {
	fmt.Println(mathx.Min(1))
	fmt.Println(mathx.Min(1, 2))
	fmt.Println(mathx.Min(1, 2, 0.5))
}
Output:
1
1
0.5

func Product

func Product(first float64, rest ...float64) float64

Returns a the product value multiplied by the given values.

Example
package main

import (
	"fmt"

	"github.com/ayonli/goext/mathx"
)

func main() {
	fmt.Println(mathx.Product(1))
	fmt.Println(mathx.Product(1, 2))
	fmt.Println(mathx.Product(1, 2, 0.5))
}
Output:
1
2
1

func Sum

func Sum(values ...float64) float64

Returns the sum value of the given values.

Example
package main

import (
	"fmt"

	"github.com/ayonli/goext/mathx"
)

func main() {
	fmt.Println(mathx.Sum(1))
	fmt.Println(mathx.Sum(1, 2))
	fmt.Println(mathx.Sum(1, 2, 0.5))
}
Output:
1
3
3.5

Types

This section is empty.

Jump to

Keyboard shortcuts

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