element

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 4 Imported by: 0 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

Overview

Package element provides the element types of typed arrays and the encodings of their elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(from, to Type, x uint64) uint64

Convert returns the encoding x of an element of the type from as an element of the type to, as reading the element and storing the value would. Both types must be BigInt types or neither.

func DecodeNumber

func DecodeNumber(t Type, x uint64) float64

DecodeNumber returns the number that the encoding x of an element of the type t, which is not a BigInt type, stands for.

func EncodeBigInt

func EncodeBigInt(i *big.Int) uint64

EncodeBigInt returns i modulo 2^64, the encoding of i as an element of a BigInt type.

func EncodeNumber

func EncodeNumber(t Type, f float64) uint64

EncodeNumber returns the encoding of the number f as an element of the type t, which is not a BigInt type.

func Equal

func Equal(t Type, x, y uint64) bool

Equal reports whether the encodings x and y are equal in the size of an element of the type t.

func Load

func Load(b []byte, t Type) uint64

Load returns the encoding of the element of the type t at the start of b in little-endian byte order.

func LoadEndian

func LoadEndian(b []byte, t Type, littleEndian bool) uint64

LoadEndian returns the encoding of the element of the type t at the start of b in the given byte order.

func Store

func Store(b []byte, t Type, x uint64)

Store stores the encoding x of an element of the type t at the start of b in little-endian byte order.

func StoreEndian

func StoreEndian(b []byte, t Type, x uint64, littleEndian bool)

StoreEndian stores the encoding x of an element of the type t at the start of b in the given byte order.

func StoreNumber

func StoreNumber(b []byte, t Type, f float64)

StoreNumber stores the number f as an element of the type t, which is not a BigInt type, at the start of b in little-endian byte order.

Types

type Type

type Type uint8

Type is the element type of a typed array.

const (
	Int8 Type = iota
	Uint8
	Uint8Clamped
	Int16
	Uint16
	Int32
	Uint32
	Float16
	Float32
	Float64
	BigInt64
	BigUint64

	// TypeCount is the number of element types.
	TypeCount
)

func (Type) IsBigInt

func (t Type) IsBigInt() bool

IsBigInt reports whether the elements of t are BigInts.

func (Type) IsInteger

func (t Type) IsInteger() bool

IsInteger reports whether t is an integer type that is not Uint8Clamped, as the Atomics functions require.

func (Type) Size

func (t Type) Size() int

Size returns the element size of t in bytes.

Jump to

Keyboard shortcuts

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