intspec

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 1 Imported by: 4

README

Intspec

Go Reference Go Report Card Coverage Status

Purpose

Library that provides to detect the parameters of integer types: minimum, maximum values ​​and bit size

Usage

Example:

package main

import (
    "fmt"

    "github.com/akramarenkov/intspec"
)

func main() {
    minimum, maximum := intspec.Range[int8]()
    fmt.Println(minimum)
    fmt.Println(maximum)
    // Output:
    // -128
    // 127
}

Documentation

Overview

Library that provides to detect the parameters of integer types: minimum, maximum values ​​and bit size.

Index

Examples

Constants

View Source
const (
	BitSize64  = 64
	BitSize32  = 32
	BitSize16  = 16
	BitSize8   = 8
	BitSizeInt = BitSize32 << (^uint(0) >> (BitSize64 - 1))

	MaxUint64 = 1<<BitSize64 - 1
	MaxUint32 = 1<<BitSize32 - 1
	MaxUint16 = 1<<BitSize16 - 1
	MaxUint8  = 1<<BitSize8 - 1
	MaxUint   = 1<<BitSizeInt - 1

	MaxInt64 = 1<<(BitSize64-1) - 1
	MinInt64 = -1 << (BitSize64 - 1)
	MaxInt32 = 1<<(BitSize32-1) - 1
	MinInt32 = -1 << (BitSize32 - 1)
	MaxInt16 = 1<<(BitSize16-1) - 1
	MinInt16 = -1 << (BitSize16 - 1)
	MaxInt8  = 1<<(BitSize8-1) - 1
	MinInt8  = -1 << (BitSize8 - 1)
	MaxInt   = 1<<(BitSizeInt-1) - 1
	MinInt   = -1 << (BitSizeInt - 1)
)

Variables

This section is empty.

Functions

func BitSize

func BitSize[Type constraints.Integer]() int

Returns bit size for specified integer type.

Example
package main

import (
	"fmt"

	"github.com/akramarenkov/intspec"
)

func main() {
	bisize := intspec.BitSize[int8]()
	fmt.Println(bisize)
}
Output:
8

func Range

func Range[Type constraints.Integer]() (Type, Type)

Returns minimum and maximum values for specified integer type.

Example
package main

import (
	"fmt"

	"github.com/akramarenkov/intspec"
)

func main() {
	minimum, maximum := intspec.Range[int8]()
	fmt.Println(minimum)
	fmt.Println(maximum)
}
Output:
-128
127

Types

This section is empty.

Jump to

Keyboard shortcuts

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