PROBLEM STATEMENT
I would like to iterate over every element in a matrix and display:
- The Element Value
- The Element Index (I, J)
The code below gives me the following output:
(-2147483648, -2147483648) = 1.00000E+00
(-2147483648, -2147483647) = 2.00000E+00
(-2147483648, -2147483646) = 3.00000E+00
(-2147483647, -2147483648) = 4.00000E+00
(-2147483647, -2147483647) = 5.00000E+00
(-2147483647, -2147483646) = 6.00000E+00
I would expect to see 1 instead of -2147483648 and 2 instead of -2147483647.
SAMPLE CODE
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
with Ada.Text_IO; use Ada.Text_IO;
procedure Index is
Matrix : Real_Matrix := (( 1.0, 2.0, 3.0 ),
( 4.0, 5.0, 6.0 ));
begin
for I in Matrix'Range(1) loop
for J in Matrix'Range(2) loop
Put_Line("(" & Integer'Image(I) & ", " &
Integer'Image(J) & ") = " &
Float'Image(Matrix(I, J)));
end loop;
end loop;
end Index;