ints

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: GPL-3.0 Imports: 1 Imported by: 2

Documentation

Overview

Package ints contains functions and constants to do with integers and generating sequences of integers.

Index

Examples

Constants

View Source
const (
	MaxUint = ^uint(0)
	MinUint = 0
	MinInt  = -MaxInt - 1
	MaxInt  = int(MaxUint >> 1)
)

Variables

This section is empty.

Functions

func Max

func Max(numbers ...int) (max int)

Max returns the maximum of all the given integers.

If no numbers are given 0 is returned.

func Min

func Min(numbers ...int) (min int)

Min returns the minimum of all the given integers.

If no numbers are given 0 is returned.

func Ordinal added in v1.2.5

func Ordinal(x int) string

Ordinal gives you the input number in a rank/ordinal format.

Ordinal(3) -> 3rd. Straight from the "go-humanize" library: https://github.com/dustin/go-humanize.

Example

Generates the ordinals for 1, 2 and 3.

fmt.Println(Ordinal(1), Ordinal(2), Ordinal(3))
Output:
1st 2nd 3rd

func Range

func Range(start, end, step int) []int

Range generates an integer array with indices from start to end with the given step value.

Returns an empty array if step is equal to 0 or end is less than start and step is a positive number.

Example

Counting down from 10 in intervals of 2.

The Range function is similar to the range function in Python.

r := Range(10, 0, -2)
fmt.Println(r)
Output:
[10 8 6 4 2 0]

Types

This section is empty.

Jump to

Keyboard shortcuts

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