num

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: BSD-3-Clause Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Signed | Float](x T) T

Abs returns the absolute value of the given value.

func FromBool

func FromBool[T Number](v bool) T

FromBool returns a 1 if the bool is true and a 0 for false. Typically the type parameter cannot be inferred and must be provided. See SetFromBool for a version that uses a pointer to the destination which avoids the need to specify the type parameter.

func SetFromBool

func SetFromBool[T Number](dst *T, b bool)

SetFromBool converts a bool into a number, using generics, setting the pointer to the dst destination value to a 1 if bool is true, and 0 otherwise. This version of FromBool does not require type parameters typically.

func ToBool

func ToBool[T Number](v T) bool

ToBool returns a bool true if the given number is not zero, and false if it is zero, providing a direct way to convert numbers to bools as is done automatically in C and other languages.

Types

type Complex

type Complex interface {
	~complex64 | ~complex128
}

Complex is a constraint that permits any complex numeric type. If future releases of Go add new predeclared complex numeric types, this constraint will be modified to include them.

type Float

type Float interface {
	~float32 | ~float64
}

Float is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.

type Integer

type Integer interface {
	Signed | Unsigned
}

Integer is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.

type Number

type Number interface {
	Integer | Float
}

Number is a constraint that permits any single-valued numerical type, i.e., Integer or Float. It excludes complex numbers.

type Ordered

type Ordered interface {
	Integer | Float | ~string
}

Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Signed is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.

Jump to

Keyboard shortcuts

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