Integer and Float Primitives¶
Importing fixed length primitive types.
[1]:
from itertools import chain
from byteclasses.print import byteclass_info, byteclass_inspect
from byteclasses.types.primitives.floats import Double, Float, Float16, Float32, Float64, Half
from byteclasses.types.primitives.integers import (
Int,
Int8,
Int16,
Int32,
Int64,
Long,
LongLong,
Ptr16,
Ptr32,
Ptr64,
Short,
UInt,
UInt8,
UInt16,
UInt32,
UInt64,
ULong,
ULongLong,
UnderflowError,
UShort,
)
Fixed Size Primitive Instantiation
[2]:
fixed_integer_types = [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Long, ULong]
fixed_integer_type_aliases = [Ptr16, Ptr32, Ptr64, Short, UShort, Int, UInt, LongLong, ULongLong]
fixed_float_types = [Float16, Float32, Float64]
fixed_float_type_aliases = [Half, Float, Double]
[3]:
for i, type_cls in enumerate(
chain(fixed_integer_types, fixed_integer_type_aliases, fixed_float_types, fixed_float_type_aliases)
):
var = type_cls(i)
byteclass_info(var)
byteclass_inspect(var)
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int8 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int8 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 1 │ │ str() │ 0 │ │ repr() │ Int8(0) │ │ .data │ b'\x00' │ │ .value │ 0 │ └──────────────────────────┴──────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 0 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int16 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 1 │ │ repr() │ Int16(1) │ │ .data │ b'\x01\x00' │ │ .value │ 1 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |01 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 1 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int32 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 2 │ │ repr() │ Int32(2) │ │ .data │ b'\x02\x00\x00\x00' │ │ .value │ 2 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |02 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 2 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int64 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 3 │ │ repr() │ Int64(3) │ │ .data │ b'\x03\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 3 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |03 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 3 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt8 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt8 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 1 │ │ str() │ 4 │ │ repr() │ UInt8(4) │ │ .data │ b'\x04' │ │ .value │ 4 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |04 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 4 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt16 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 5 │ │ repr() │ UInt16(5) │ │ .data │ b'\x05\x00' │ │ .value │ 5 │ └──────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |05 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 5 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt32 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 6 │ │ repr() │ UInt32(6) │ │ .data │ b'\x06\x00\x00\x00' │ │ .value │ 6 │ └──────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |06 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 6 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt64 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 7 │ │ repr() │ UInt64(7) │ │ .data │ b'\x07\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 7 │ └──────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |07 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 7 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Long │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Long -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 8 │ │ repr() │ Long(8) │ │ .data │ b'\x08\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 8 │ └──────────────────────────┴──────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |08 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 8 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ ULong │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ ULong -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 9 │ │ repr() │ ULong(9) │ │ .data │ b'\t\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 9 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |09 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 9 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Ptr16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Ptr16 -> UInt16 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 0x000a │ │ repr() │ Ptr16(0xa) │ │ .data │ b'\n\x00' │ │ .value │ 10 │ └──────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |0a 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━┩ │ 0x000a │ └────────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Ptr32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Ptr32 -> UInt32 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 0x0000000b │ │ repr() │ Ptr32(0xb) │ │ .data │ b'\x0b\x00\x00\x00' │ │ .value │ 11 │ └──────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |0b 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━━━━━┩ │ 0x0000000b │ └────────────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Ptr64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Ptr64 -> UInt64 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 0x000000000000000c │ │ repr() │ Ptr64(0xc) │ │ .data │ b'\x0c\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 12 │ └──────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |0c 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━━━━━━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━┩ │ 0x000000000000000c │ └────────────────────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int16 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 13 │ │ repr() │ Int16(13) │ │ .data │ b'\r\x00' │ │ .value │ 13 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |0d 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 13 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt16 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 14 │ │ repr() │ UInt16(14) │ │ .data │ b'\x0e\x00' │ │ .value │ 14 │ └──────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |0e 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 14 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int32 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 15 │ │ repr() │ Int32(15) │ │ .data │ b'\x0f\x00\x00\x00' │ │ .value │ 15 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |0f 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 15 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt32 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 16 │ │ repr() │ UInt32(16) │ │ .data │ b'\x10\x00\x00\x00' │ │ .value │ 16 │ └──────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |10 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 16 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Int64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Int64 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 17 │ │ repr() │ Int64(17) │ │ .data │ b'\x11\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 17 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |11 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 17 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ UInt64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ UInt64 -> _PrimitiveInt -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 18 │ │ repr() │ UInt64(18) │ │ .data │ b'\x12\x00\x00\x00\x00\x00\x00\x00' │ │ .value │ 18 │ └──────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |12 00 00 00 00 00 00 00 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 18 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Float16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Float16 -> _FixedFloat -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 19.0 │ │ repr() │ Float16(19.0) │ │ .data │ b'\xc0L' │ │ .value │ 19.0 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |c0 4c │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 19.0 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Float32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Float32 -> _FixedFloat -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 20.0 │ │ repr() │ Float32(20.0) │ │ .data │ b'\x00\x00\xa0A' │ │ .value │ 20.0 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |00 00 a0 41 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 20.0 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Float64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Float64 -> _FixedFloat -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 21.0 │ │ repr() │ Float64(21.0) │ │ .data │ b'\x00\x00\x00\x00\x00\x005@' │ │ .value │ 21.0 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |00 00 00 00 00 00 35 40 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 21.0 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Float16 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Float16 -> _FixedFloat -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 2 │ │ str() │ 22.0 │ │ repr() │ Float16(22.0) │ │ .data │ b'\x80M' │ │ .value │ 22.0 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |80 4d │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 22.0 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Float32 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Float32 -> _FixedFloat -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 4 │ │ str() │ 23.0 │ │ repr() │ Float32(23.0) │ │ .data │ b'\x00\x00\xb8A' │ │ .value │ 23.0 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |00 00 b8 41 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 23.0 │ └───────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Float64 │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Float64 -> _FixedFloat -> _PrimitiveNumber -> _Primitive -> ABC -> object │ │ len() │ 8 │ │ str() │ 24.0 │ │ repr() │ Float64(24.0) │ │ .data │ b'\x00\x00\x00\x00\x00\x008@' │ │ .value │ 24.0 │ └──────────────────────────┴───────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |00 00 00 00 00 00 38 40 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 24.0 │ └───────┘
Numeric byteclasses can be used in math operations just like normal numbers
[4]:
var1 = UInt8(1)
var2 = UInt8(2)
print(var1, var2, var1 + var2)
1 2 3
[5]:
var1 = UInt8(1)
var2 = 2
print(var1, var2, var1 + var2)
1 2 3
[6]:
var1 = 1
var2 = UInt8(2)
print(var1, var2, var1 + var2)
1 2 3
Each primitive class has built-in bounds checks and will raise an OverflowError
or UnderflowError
as appropriate.
[7]:
try:
_ = Int8(128)
except OverflowError as err:
print(err)
try:
_ = UInt8(-1)
except UnderflowError as err:
print(err)
OverfowError: value (128) exceeded Int8 max (127)
UnderfowError: value (-1) below UInt8 min (0)
Override Overflow Protection¶
[8]:
overflow_var = Int8(128, allow_overflow=True)
byteclass_inspect(overflow_var)
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |80 │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ -128 │ └───────┘
[9]:
underflow_var = UInt8(-1, allow_overflow=True)
byteclass_inspect(underflow_var)
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |ff │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━┩ │ 255 │ └───────┘
Attaching to external data¶
[10]:
my_data = bytearray(b"\x00\x01\x02\x03")
mv = memoryview(my_data)
my_var1 = Int32()
my_var2 = UInt32()
print(my_data, my_var1, my_var2)
bytearray(b'\x00\x01\x02\x03') 0 0
Any byteclass instance can be attached to a memoryview of equal size
[11]:
my_var1.attach(mv)
my_var2.attach(mv)
print(my_data, my_var1, my_var2)
bytearray(b'\x00\x00\x00\x00') 0 0
Changes to data are also represented in any attached byteclass instances
[12]:
mv[:] = b"\x04\x05\x06\x07"
print(my_data, my_var1, my_var2)
bytearray(b'\x04\x05\x06\x07') 117835012 117835012
Changes to a primitive’s value or data attribute are also applied to the attached data
[13]:
my_var1.value = my_var1.max
print(my_data, my_var1, my_var2)
bytearray(b'\xff\xff\xff\x7f') 2147483647 2147483647
Changes to a primitive’s value or data attribute are also applied to the attached data
[14]:
my_var2.value = my_var2.max
print(my_data, my_var1, my_var2)
bytearray(b'\xff\xff\xff\xff') -1 4294967295