bmnumbers

package
v0.0.0-...-3be6dbe Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

README

bmnumbers

bmstack is part of BondMachine project. bmnumbers is both a command line tool to convert or cast numbers to and from different formats and a library to do the same. It is used within the BondMachine every time numbers are handled.

Supported number types

The supported number types are listed in the following table.

Type Name Prefixes Description Static Lenght
unsigned none
0u
0d
Unsigned integer yes any
signed 0s
0sd
Signed integer yes any
bin 0b
0b<s>
Binary number yes any
s bits
hex 0x Hexadecimal number yes any
float16 0f<16> IEEE 754 half precision floating point number yes 16 bits
float32 0f
0f<32>
IEEE 754 single precision floating point number yes 32 bits
lqs[s]t[t] 0lq<s.t> Linear quantized number with size s and type t no s bits
fps[s]f[f] 0fp<s.f> Fixed point number with size s and fraction f no s bits
flp[e]f[f] 0flp<e.f> FloPoCo floating point number with exponent e and mantissa f no e+f+3 bits

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllDynamicalTypes []DynamicalType
View Source
var AllMatchers map[string]ImportFunc
View Source
var AllTypes []BMNumberType

Functions

func CastType

func CastType(n *BMNumber, t BMNumberType) error

func EventuallyCreateType

func EventuallyCreateType(name string, param interface{}) (bool, error)

func ListTypes

func ListTypes()

func LoadLinearDataRangesFromFile

func LoadLinearDataRangesFromFile(filename string) error

func Serve

func Serve(conf *BMNumberConfig)

REST API to convert numbers

Types

type BMNumber

type BMNumber struct {
	// contains filtered or unexported fields
}

BMNumber is a binary representation of a number as a slice of bytes

func ImportBytes

func ImportBytes(input []byte, bits int) (*BMNumber, error)

func ImportString

func ImportString(input string) (*BMNumber, error)

InitBMNumber creates a new BMNumber for a string

func ImportUint

func ImportUint(input interface{}, optionalBits int) (*BMNumber, error)

func (*BMNumber) ExportBinary

func (n *BMNumber) ExportBinary(withSize bool) (string, error)

func (*BMNumber) ExportBinaryNBits

func (n *BMNumber) ExportBinaryNBits(bits int) (string, error)

func (*BMNumber) ExportString

func (n *BMNumber) ExportString(c *BMNumberConfig) (string, error)

func (*BMNumber) ExportUint64

func (n *BMNumber) ExportUint64() (uint64, error)

func (*BMNumber) ExportVerilogBinary

func (n *BMNumber) ExportVerilogBinary() (string, error)

func (*BMNumber) GetBytes

func (n *BMNumber) GetBytes() []byte

func (*BMNumber) GetTypeName

func (n *BMNumber) GetTypeName() string

type BMNumberConfig

type BMNumberConfig struct {
	OmitPrefix bool
}

type BMNumberServer

type BMNumberServer struct {
	// contains filtered or unexported fields
}

func (*BMNumberServer) ExecRequest

func (s *BMNumberServer) ExecRequest(w http.ResponseWriter, r *http.Request)

func (*BMNumberServer) HomePage

func (s *BMNumberServer) HomePage(w http.ResponseWriter, r *http.Request)

type BMNumberType

type BMNumberType interface {
	GetName() string

	GetSize() int

	Convert(*BMNumber) error
	ExportString(*BMNumber) (string, error)
	ShowInstructions() map[string]string
	ShowPrefix() string
	// contains filtered or unexported methods
}

func GetType

func GetType(name string) BMNumberType

type BMNumbersRequest

type BMNumbersRequest struct {
	Action   string   `json:"action"`
	Numbers  []string `json:"numbers"`
	ReqType  string   `json:"reqType"`
	DumpMode string   `json:"viewMode"`
}

type BMNumbersResponse

type BMNumbersResponse struct {
	Numbers []string `json:"numbers"`
}

type Bin

type Bin struct{}

func (Bin) Convert

func (d Bin) Convert(n *BMNumber) error

func (Bin) ExportString

func (d Bin) ExportString(n *BMNumber) (string, error)

func (Bin) GetName

func (d Bin) GetName() string

func (Bin) GetSize

func (d Bin) GetSize() int

func (Bin) ShowInstructions

func (d Bin) ShowInstructions() map[string]string

func (Bin) ShowPrefix

func (d Bin) ShowPrefix() string

type DynFixedPoint

type DynFixedPoint struct {
}

func (DynFixedPoint) CreateType

func (d DynFixedPoint) CreateType(name string, param interface{}) (BMNumberType, error)

func (DynFixedPoint) GetName

func (d DynFixedPoint) GetName() string

func (DynFixedPoint) MatchName

func (d DynFixedPoint) MatchName(name string) bool

type DynFloPoCo

type DynFloPoCo struct{}

func (DynFloPoCo) CreateType

func (d DynFloPoCo) CreateType(name string, param interface{}) (BMNumberType, error)

func (DynFloPoCo) GetName

func (d DynFloPoCo) GetName() string

func (DynFloPoCo) MatchName

func (d DynFloPoCo) MatchName(name string) bool

type DynLinearQuantizer

type DynLinearQuantizer struct {
	Ranges *map[int]LinearDataRange
}

func (DynLinearQuantizer) CreateType

func (d DynLinearQuantizer) CreateType(name string, param interface{}) (BMNumberType, error)

func (DynLinearQuantizer) GetName

func (d DynLinearQuantizer) GetName() string

func (DynLinearQuantizer) MatchName

func (d DynLinearQuantizer) MatchName(name string) bool

type DynamicalType

type DynamicalType interface {
	GetName() string
	MatchName(string) bool
	CreateType(string, interface{}) (BMNumberType, error)
}

type FixedPoint

type FixedPoint struct {
	FixedPointName string
	// contains filtered or unexported fields
}

func (FixedPoint) Convert

func (d FixedPoint) Convert(n *BMNumber) error

func (FixedPoint) ExportString

func (d FixedPoint) ExportString(n *BMNumber) (string, error)

func (FixedPoint) GetName

func (d FixedPoint) GetName() string

func (FixedPoint) GetSize

func (d FixedPoint) GetSize() int

func (FixedPoint) ShowInstructions

func (d FixedPoint) ShowInstructions() map[string]string

func (FixedPoint) ShowPrefix

func (d FixedPoint) ShowPrefix() string

type FloPoCo

type FloPoCo struct {
	// contains filtered or unexported fields
}

func (FloPoCo) Convert

func (d FloPoCo) Convert(n *BMNumber) error

func (FloPoCo) ExportString

func (d FloPoCo) ExportString(n *BMNumber) (string, error)

func (FloPoCo) GetName

func (d FloPoCo) GetName() string

func (FloPoCo) GetSize

func (d FloPoCo) GetSize() int

func (FloPoCo) ShowInstructions

func (d FloPoCo) ShowInstructions() map[string]string

func (FloPoCo) ShowPrefix

func (d FloPoCo) ShowPrefix() string

type Float16

type Float16 struct{}

func (Float16) Convert

func (d Float16) Convert(n *BMNumber) error

func (Float16) ExportString

func (d Float16) ExportString(n *BMNumber) (string, error)

func (Float16) GetName

func (d Float16) GetName() string

func (Float16) GetSize

func (d Float16) GetSize() int

func (Float16) ShowInstructions

func (d Float16) ShowInstructions() map[string]string

func (Float16) ShowPrefix

func (d Float16) ShowPrefix() string

type Float32

type Float32 struct{}

func (Float32) Convert

func (d Float32) Convert(n *BMNumber) error

func (Float32) ExportString

func (d Float32) ExportString(n *BMNumber) (string, error)

func (Float32) GetName

func (d Float32) GetName() string

func (Float32) GetSize

func (d Float32) GetSize() int

func (Float32) ShowInstructions

func (d Float32) ShowInstructions() map[string]string

func (Float32) ShowPrefix

func (d Float32) ShowPrefix() string

type Hex

type Hex struct{}

func (Hex) Convert

func (d Hex) Convert(n *BMNumber) error

func (Hex) ExportString

func (b Hex) ExportString(n *BMNumber) (string, error)

func (Hex) GetName

func (d Hex) GetName() string

func (Hex) GetSize

func (d Hex) GetSize() int

func (Hex) ShowInstructions

func (b Hex) ShowInstructions() map[string]string

func (Hex) ShowPrefix

func (b Hex) ShowPrefix() string

type ImportFunc

type ImportFunc func(*regexp.Regexp, string) (*BMNumber, error)

type LinearDataRange

type LinearDataRange struct {
	Max float64
}

type LinearQuantizer

type LinearQuantizer struct {
	// contains filtered or unexported fields
}

func (LinearQuantizer) Convert

func (d LinearQuantizer) Convert(n *BMNumber) error

func (LinearQuantizer) ExportString

func (d LinearQuantizer) ExportString(n *BMNumber) (string, error)

func (LinearQuantizer) GetName

func (d LinearQuantizer) GetName() string

func (LinearQuantizer) GetSize

func (d LinearQuantizer) GetSize() int

func (LinearQuantizer) ShowInstructions

func (d LinearQuantizer) ShowInstructions() map[string]string

func (LinearQuantizer) ShowPrefix

func (d LinearQuantizer) ShowPrefix() string

type Signed

type Signed struct{}

func (Signed) Convert

func (d Signed) Convert(n *BMNumber) error

func (Signed) ExportString

func (d Signed) ExportString(n *BMNumber) (string, error)

func (Signed) GetName

func (d Signed) GetName() string

func (Signed) GetSize

func (d Signed) GetSize() int

func (Signed) ShowInstructions

func (d Signed) ShowInstructions() map[string]string

func (Signed) ShowPrefix

func (d Signed) ShowPrefix() string

type Unsigned

type Unsigned struct{}

func (Unsigned) Convert

func (d Unsigned) Convert(n *BMNumber) error

func (Unsigned) ExportString

func (d Unsigned) ExportString(n *BMNumber) (string, error)

func (Unsigned) GetName

func (d Unsigned) GetName() string

func (Unsigned) GetSize

func (d Unsigned) GetSize() int

func (Unsigned) ShowInstructions

func (d Unsigned) ShowInstructions() map[string]string

func (Unsigned) ShowPrefix

func (d Unsigned) ShowPrefix() string

Jump to

Keyboard shortcuts

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