3 ms·
Ada mod takes the sign of the second operand. I wouldn't even bother with this, I'd just use a modular type (i.e. unsigned). with Ada.Text_IO; pr
by pyjarrett 5y ago
Ada mod takes the sign of the second operand.
I wouldn't even bother with this, I'd just use a modular type (i.e. unsigned).
with Ada.Text_IO;
procedure Main is
-- Modular type (unsigned) which can take values of [0, 15].
type Nibble is mod 16;
Value : Nibble := 0;
begin
-- Prints 0 3 6 9 12 15 2 5 8 11 14 1 4 7 10 13 ...
for I in 0 .. 63 loop
Ada.Text_IO.Put_Line (Value'Image);
Value := Value + 3;
end loop;
end Main;
Then make that type the index into my circular buffer and then I never need to worry about it.
type Circular_Buffer is array (Nibble) of Integer;
Buffer : Circular_Buffer;