math

package
v0.0.0-...-02e3eee Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: GPL-3.0, LGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt

func AbsInt[N types.SignedInteger](n N) N

AbsInt determines the absolute value of provided integer.

func Difference

func Difference[N types.Integer](a, b N) N

Difference computes an absolute value that's the difference between `a` and `b`.

func Even

func Even[N types.Integer](x N) bool

func GCD

func GCD[N types.UnsignedInteger](a, b N) N

GCD is a unoptimized, inefficient version of the Greatest Common Divisor.

Using Euclidian algorithm, following [1]: `gcd(a, b) == gcd(b, a mod b)` for `a > b`. Perform repeatedly until `gcd(x, 0)`, at which point `x` is greatest common divisor for `gcd(a,b)`.

[1]: <https://en.wikipedia.org/wiki/Greatest_common_divisor>

func LCM

func LCM[N types.UnsignedInteger](a, b N) N

LCM is a unoptimized version of the Least/Lowest Common Multiple.

Using the Greatest Common Divisor, following [1]: `lcm(a,b) = |ab| / gcd(a,b)`

[1]: <https://en.wikipedia.org/wiki/Least_common_multiple>

func Max

func Max[N types.Integer](x, y N) N

Max returns the maximum of two values.

func MaxN

func MaxN[N types.Integer](x ...N) N

MaxN returns the maximum of vararg provided number of values. At least one value must be provided or the function will panic.

func Min

func Min[N types.Integer](x, y N) N

Min returns the minimum of two values.

func MinN

func MinN[N types.Integer](x ...N) N

MinN returns the minimum of vararg provided number of values.

func Odd

func Odd[N types.Integer](x N) bool

func PowUint

func PowUint[U types.UnsignedInteger](base, power U) U

PowUint calculates a power of a given base for an arbitrary base value.

NOTE: this function is not optimized for very large calculations and care should be taken to choose a data-type with sufficient space to contain the result.

func Sign

func Sign[N types.Integer](x N) int

Sign returns the sign of the provided value: `1` for positive value, `0` for zero, `-1` for negative value.

Types

This section is empty.

Directories

Path Synopsis
modular provides arithmetic functions for modular arithmetic.
modular provides arithmetic functions for modular arithmetic.

Jump to

Keyboard shortcuts

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