digit

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package digit is a package of generic-type functions for digit.

Index

Constants

View Source
const (
	Host64bit = strconv.IntSize == 64
	Host32bit = ^uint(0)>>32 == 0
)

Variables

This section is empty.

Functions

func Abs

func Abs[T gust.Digit](d T) T

func AppendInt added in v1.1.0

func AppendInt(dst []byte, i int64, base int) []byte

AppendInt appends the string form of the integer i, as generated by FormatInt, to dst and returns the extended buffer. NOTE:

Compatible with standard package strconv.

func AppendUint added in v1.1.0

func AppendUint(dst []byte, i uint64, base int) []byte

AppendUint appends the string form of the unsigned integer i, as generated by FormatUint, to dst and returns the extended buffer. NOTE:

Compatible with standard package strconv.

func As added in v1.1.0

func As[T gust.Digit, D gust.Digit](v T) gust.Result[D]

func Atoi added in v1.1.0

func Atoi(s string) (int, error)

Atoi is equivalent to ParseInt(s, 10, 0), converted to type int.

func CheckedAdd added in v1.0.0

func CheckedAdd[T gust.Integer](a, b T) gust.Option[T]

func CheckedMul added in v1.1.0

func CheckedMul[T gust.Integer](a, b T) gust.Option[T]

func FormatByDict added in v1.1.0

func FormatByDict(dict []byte, num uint64) string

FormatByDict convert num into corresponding string according to dict.

func FormatInt added in v1.1.0

func FormatInt(i int64, base int) string

FormatInt returns the string representation of i in the given base, for 2 <= base <= 62. NOTE:

Compatible with standard package strconv.

func FormatUint added in v1.1.0

func FormatUint(i uint64, base int) string

FormatUint returns the string representation of i in the given base, for 2 <= base <= 62. NOTE:

Compatible with standard package strconv.

func FromBool added in v1.1.0

func FromBool[T ~bool, D gust.Digit](v T) D

FromBool converts bool to digit.

func FromBools added in v1.1.0

func FromBools[T ~bool, D gust.Digit](a []T) (b []D)

func Itoa added in v1.1.0

func Itoa(i int) string

Itoa is equivalent to FormatInt(int64(i), 10). NOTE:

Compatible with standard package strconv.

func Max added in v1.0.0

func Max[T gust.Integer]() T

func ParseByDict added in v1.1.0

func ParseByDict[D gust.Digit](dict []byte, numStr string) gust.Result[D]

ParseByDict convert numStr into corresponding digit according to dict.

func ParseInt added in v1.1.0

func ParseInt(s string, base int, bitSize int) gust.Result[int64]

ParseInt interprets a string s in the given base (0, 2 to 62) and bit size (0 to 64) and returns the corresponding value i.

If base == 0, the base is implied by the string's prefix: base 2 for "0b", base 8 for "0" or "0o", base 16 for "0x", and base 10 otherwise. Also, for base == 0 only, underscore characters are permitted per the Go integer literal syntax. If base is below 0, is 1, or is above 62, an error is returned.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64. If bitSize is below 0 or above 64, an error is returned.

The errors that ParseInt returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax and the returned value is 0; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange and the returned value is the maximum magnitude integer of the appropriate bitSize and sign. NOTE:

Compatible with standard package strconv.

func ParseUint added in v1.1.0

func ParseUint(s string, base int, bitSize int) gust.Result[uint64]

ParseUint is like ParseInt but for unsigned numbers. NOTE:

Compatible with standard package strconv.

func SaturatingAdd added in v1.0.0

func SaturatingAdd[T gust.Integer](a, b T) T

func SaturatingSub added in v1.0.0

func SaturatingSub[T gust.Digit](a, b T) T

func SliceAs added in v1.1.0

func SliceAs[T gust.Digit, D gust.Digit](a []T) (b []D, err error)

SliceAs creates a copy of the digit slice.

func ToBool added in v1.1.0

func ToBool[T gust.Digit](v T) bool

ToBool converts D to bool.

func ToBools added in v1.1.0

func ToBools[T gust.Digit](a []T) []bool

ToBools converts []D to []bool.

func TryFromString added in v1.1.0

func TryFromString[T ~string, D gust.Digit](v T, base int, bitSize int) gust.Result[D]

TryFromString converts ~string to digit. If base == 0, the base is implied by the string's prefix: base 2 for "0b", base 8 for "0" or "0o", base 16 for "0x", and base 10 otherwise. Also, for base == 0 only, underscore characters are permitted per the Go integer literal syntax. If base is below 0, is 1, or is above 62, an error is returned.

func TryFromStrings added in v1.1.0

func TryFromStrings[T ~string, D gust.Digit](a []T, base int, bitSize int) gust.Result[[]D]

Types

This section is empty.

Jump to

Keyboard shortcuts

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