Class BSV::Script::ScriptNumber ¶
Inherits: Object Includes: Comparable
Bitcoin script number: arbitrary-precision integer with sign-magnitude little-endian byte encoding.
Script numbers use a specialised encoding where the sign bit occupies the MSB of the last byte, and the magnitude is stored little-endian. This class handles encoding/decoding, minimal encoding validation, and arithmetic operations as required by the script interpreter.
Constants¶
INT32_MAX ¶
Maximum 32-bit signed integer value.
INT32_MIN ¶
Minimum 32-bit signed integer value.
MAX_BYTE_LENGTH ¶
Maximum byte length for script numbers (post-Genesis: 750 KB).
Attributes¶
value [R] ¶
- @return [Integer] the numeric value
Public Class Methods¶
from_bytes(bytes, max_length: = MAX_BYTE_LENGTH, require_minimal: = false) ¶
Decode little-endian sign-magnitude bytes into a ScriptNumber.
Encoding: little-endian magnitude with sign bit in the MSB of the last byte. 127 -> [0x7f] -127 -> [0xff] 128 -> [0x80 0x00] -128 -> [0x80 0x80] 256 -> [0x00 0x01] -256 -> [0x00 0x81]
minimally_encode(data) ¶
Strip trailing zero-padding while preserving sign.
Public Instance Methods¶
%(other) ¶
Remainder with sign of dividend (matching Bitcoin consensus). - @raise [ScriptError]
*(other) ¶
Not documented.
+(other) ¶
--- Arithmetic (returns new ScriptNumber) ---
-(other) ¶
Not documented.
-@() ¶
Not documented.
/(other) ¶
Truncated-toward-zero division (matching Bitcoin consensus). - @raise [ScriptError]
<=>(other) <a id="<=>-instance_method">¶
Not documented.
abs() ¶
Not documented.
initialize(value) ¶
- @return [ScriptNumber] a new instance of ScriptNumber
to_bytes() ¶
Encode as little-endian sign-magnitude bytes.
to_i() ¶
Not documented.
to_i32() ¶
Clamp to int32 range (for opcodes that need bounded indices).
zero?() ¶
- @return [Boolean]