| 1 |
-- { dg-do compile } |
| 2 |
-- { dg-options "-O -gnatws" } |
| 3 |
|
| 4 |
package body Opt1 is |
| 5 |
|
| 6 |
function De_Linear_Index |
| 7 |
(Index : Natural; |
| 8 |
D : Natural; |
| 9 |
Ind_Lengths : Dimention_Length) |
| 10 |
return Dimension_Indexes |
| 11 |
is |
| 12 |
Len : Natural := 1; |
| 13 |
Tmp_Ind : Natural := Index; |
| 14 |
Tmp_Res : Natural; |
| 15 |
Result : Dimension_Indexes (1 .. D); |
| 16 |
begin |
| 17 |
for J in 1 .. D loop |
| 18 |
Len := Len * Ind_Lengths (J); |
| 19 |
end loop; |
| 20 |
|
| 21 |
for J in Result'Range loop |
| 22 |
Result (J) := Tmp_Res; |
| 23 |
Tmp_Ind := Tmp_Ind - Len * (Result (J) - 1); |
| 24 |
end loop; |
| 25 |
|
| 26 |
return Result; |
| 27 |
end; |
| 28 |
|
| 29 |
end Opt1; |