On this page
Verada.Vibe.Integers
Python's shift operators on Integer, for Vibe.
Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.
Availability and ownership
Shift_Left and Shift_Right are Python's << and >> on Integer: a product by a power of two, whose overflow and negative counts are excluded by the precondition, and a division rounding down. Powers_Of_Two and Power_Of_Two state them. The compiler uses this unit when it translates Vibe; programs do not need to import it.
A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.
Import and instantiate
with Verada.Vibe.Integers;import Verada.Vibe.Integers;
A Vibe module imports this unit's names with from Verada.Vibe.Integers import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.
Contract and lifecycle reading
A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.
API 001
Power_Table (declaration) — The array type of Powers_Of_Two: one Long_Long_Long_Integer for each exponent 0 .. 64.
Declared interface:
type Power_Table is array (0 .. 64) of Long_Long_Long_Integer;API 002
Powers_Of_Two (declaration) — 2 ** I at index I, for I in 0 .. 64.
Declared interface:
Powers_Of_Two : constant Power_Table :=
(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432,
67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296,
8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944,
549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208,
17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656,
562949953421312, 1125899906842624, 2251799813685248, 4503599627370496,
9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936,
144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976,
2305843009213693952, 4611686018427387904, 9223372036854775808,
18446744073709551616);API 003
Power_Of_Two (declaration) — 2 ** Count for a Count up to 64, read from Powers_Of_Two; its postcondition gives the bounds the shift contracts use.
Before this operation, establish:
Count <= 64On normal return the declared contract establishes:
Power_Of_Two'Result in 1 .. 2 ** 64
and then (if Count <= 63 then Power_Of_Two'Result <= 2 ** 63)
and then (if Count >= 1 then Power_Of_Two'Result mod 2 = 0)API 004
Shift_Left (declaration) — Python's x << n: Value times 2 ** Count. The precondition excludes a negative count (Python's ValueError) and a result outside Integer (Vibe's overflow); zero shifts by any count.
Before this operation, establish:
Count >= 0
and then (Value = 0
or else (Count <= 63
and then Long_Long_Long_Integer (Value) * Power_Of_Two (Count)
in Long_Long_Long_Integer (Integer'First) .. Long_Long_Long_Integer (Integer'Last)))On normal return the declared contract establishes:
(if Value = 0 then Shift_Left'Result = 0
else Long_Long_Long_Integer (Shift_Left'Result) = Long_Long_Long_Integer (Value) * Power_Of_Two (Count))API 005
Shift_Right (declaration) — Python's x >> n: the floor of Value / 2 ** Count, so -1 >> 5 is -1, and a count of 63 or more gives 0 or -1. The count must not be negative.
Before this operation, establish:
Count >= 0On normal return the declared contract establishes:
(if Count >= 63 then Shift_Right'Result = (if Value < 0 then -1 else 0)
else Long_Long_Long_Integer (Shift_Right'Result) * Power_Of_Two (Count) <= Long_Long_Long_Integer (Value)
and then Long_Long_Long_Integer (Value) < (Long_Long_Long_Integer (Shift_Right'Result) + 1) * Power_Of_Two (Count))API 006
Bit_And (declaration) — Python's x & y of ints, two's complement as Python's ints behave; the run time's, its postcondition the bounds a client proof needs.
Declared interface:
function Bit_And (X, Y : Integer) return Integer
with Import, Convention => Ada, External_Name => "verada_rt_bit_and",
Global => null,
Post => (if X >= 0 then Bit_And'Result in 0 .. X)
and then (if Y >= 0 then Bit_And'Result in 0 .. Y)
and then (if X < 0 and then Y < 0 then Bit_And'Result < 0);API 007
Bit_Or (declaration) — Python's x | y of ints, two's complement; the run time's.
Declared interface:
function Bit_Or (X, Y : Integer) return Integer
with Import, Convention => Ada, External_Name => "verada_rt_bit_or",
Global => null,
Post => (if X >= 0 and then Y >= 0 then Bit_Or'Result >= X and then Bit_Or'Result >= Y)
and then (if X < 0 or else Y < 0 then Bit_Or'Result < 0);API 008
Bit_Xor (declaration) — Python's x ^ y of ints, two's complement; the run time's.
Declared interface:
function Bit_Xor (X, Y : Integer) return Integer
with Import, Convention => Ada, External_Name => "verada_rt_bit_xor",
Global => null,
Post => (if (X < 0) = (Y < 0) then Bit_Xor'Result >= 0 else Bit_Xor'Result < 0);