ints

package
v0.4.170 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: ISC Imports: 5 Imported by: 0

Documentation

Overview

Package ints provide manipulation of integer types.

Index

Constants

View Source
const (
	BitsPerByte = 8
)

Variables

View Source
var ErrNegative = errors.New("negative value")

can be tested: errors.Is(err, ints.ErrNegative)

View Source
var ErrTooLarge = errors.New("value too large")

can be tested: errors.Is(err, ints.ErrToLarge)

Functions

func IntProperties added in v0.4.75

func IntProperties[I constraints.Integer](variable ...I) (isSigned bool, maxPositive uint64, maxNegative int64, sizeof int)

IntProperties returns the properties of integer I

  • I is int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr
  • isSigned is true if I is a signed integer type
  • maxPositive is the largest positive number that can be assigned to I
  • maxNegative is the largest negative number that can be assigned to I. For unsigned types, maxNegative is 0
  • sizeof is the number of bytes I occupies: 1, 2, 4 or 8 for 8, 16, 32, 64-bit integers

func Unsigned added in v0.4.75

func Unsigned[U constraints.Unsigned, T constraints.Integer](integer T, label string) (unsigned U, err error)

Unsigned converts integer of type T to an unsigned value that fits the size of unsigned integer U

  • U is the unsigned integer returned
  • T is the input integer
  • integer T is of any integer size and may be signed
  • unsigned U is any size unsigned integer
  • error: if integer is negative or too large to be held in type U

Types

This section is empty.

Jump to

Keyboard shortcuts

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