From 2f0d9930df82cec42e266bcb2c2ca2bf65666fbc Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sat, 14 Feb 2026 18:12:26 -0300 Subject: [PATCH 01/12] Adding integer type for overlay Type declaration was missing. --- content/courses/advanced-ada/parts/data_types/numerics.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index c7cbd2b24..d0f8c8943 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3394,6 +3394,9 @@ the :ada:`Custom_Decimal_Types` package: type Int_T2_D6 is range -2 ** (T2_D6'Size - 1) .. 2 ** (T2_D6'Size - 1) - 1; + type Int_T2_D12 is + range -2 ** (T2_D12'Size - 1) .. + 2 ** (T2_D12'Size - 1) - 1; end Custom_Decimal_Types; From 818bd9a3d3802ed67afd247c94b4fbe2bbd3056b Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sat, 14 Feb 2026 18:14:12 -0300 Subject: [PATCH 02/12] Adding Gen_Show_Info procedure --- .../parts/data_types/numerics.rst | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index d0f8c8943..141baa5b0 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3403,6 +3403,56 @@ the :ada:`Custom_Decimal_Types` package: We can use an overlay to uncover the actual integer values stored on the machine when assigning values to objects of decimal type. For example: +.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types + + generic + type T_Decimal is delta <> digits <>; + type T_Int_Decimal is range <>; + procedure Gen_Show_Info (V : T_Decimal; + V_Str : String); + + with Ada.Text_IO; use Ada.Text_IO; + + procedure Gen_Show_Info (V : T_Decimal; + V_Str : String) + is + V_Int_Overlay : T_Int_Decimal + with Address => V'Address, + Import, Volatile; + V_Real : Float; + begin + V_Real := Float (V_Int_Overlay) * + T_Decimal'Small; + + Put_Line (V_Str + & " (fixed-point) : " + & V'Image); + Put_Line (V_Str + & " (integer) : " + & V_Int_Overlay'Image); + Put_Line (V_Str + & " (floating-p.) : " + & V_Real'Image); + Put_Line ("----------"); + end Gen_Show_Info; + + with Gen_Show_Info; + + package Custom_Decimal_Types.Show_Info_Procs is + + procedure Show_Info is new + Gen_Show_Info (T_Decimal => T0_D4, + T_Int_Decimal => Int_T0_D4); + procedure Show_Info is new + Gen_Show_Info (T_Decimal => T2_D6, + T_Int_Decimal => Int_T2_D6); + procedure Show_Info is new + Gen_Show_Info (T_Decimal => T2_D12, + T_Int_Decimal => Int_T2_D12); + + end Custom_Decimal_Types.Show_Info_Procs; + + .. code:: ada no_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types :class: ada-run From 38b78de2a265311e3c1edb1e9c0d4f6ddc925e26 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sat, 14 Feb 2026 18:18:11 -0300 Subject: [PATCH 03/12] Replace calls to `Put_Line` by `Show_Info` --- .../parts/data_types/numerics.rst | 62 ++++--------------- 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 141baa5b0..e3ce077d5 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3461,57 +3461,21 @@ machine when assigning values to objects of decimal type. For example: with Custom_Decimal_Types; use Custom_Decimal_Types; - procedure Show_Machine_Implementation is - V_T0_D4 : T0_D4; - V_Int_T0_D4 : Int_T0_D4 - with Address => V_T0_D4'Address, - Import, Volatile; + with Custom_Decimal_Types.Show_Info_Procs; + use Custom_Decimal_Types.Show_Info_Procs; - V_T2_D6 : T2_D6; - V_Int_T2_D6 : Int_T2_D6 - with Address => V_T2_D6'Address, - Import, Volatile; + procedure Show_Machine_Implementation is begin - V_T0_D4 := 1.0; - Put_Line ("1.0 (T0_D4) : " - & V_T0_D4'Image); - Put_Line ("1.0 (Int_T0_D4) : " - & V_Int_T0_D4'Image); - - V_T2_D6 := 1.55; - V_T0_D4 := T0_D4 (V_T2_D6); - Put_Line ("1.55 (T0_D4) : " - & V_T0_D4'Image); - Put_Line ("1.55 (Int_T0_D4) : " - & V_Int_T0_D4'Image); - - V_T0_D4 := 2.0; - Put_Line ("2.0 (T0_D4) : " - & V_T0_D4'Image); - Put_Line ("2.0 (Int_T0_D4) : " - & V_Int_T0_D4'Image); - - Put_Line ("-----------------------------"); - - V_T2_D6 := 1.0; - Put_Line ("1.00 (T2_D6) : " - & V_T2_D6'Image); - Put_Line ("1.00 (Int_T2_D6) : " - & V_Int_T2_D6'Image); - - V_T2_D6 := 1.55; - Put_Line ("1.55 (T2_D6) : " - & V_T2_D6'Image); - Put_Line ("1.55 (Int_T2_D6) : " - & V_Int_T2_D6'Image); - - V_T2_D6 := 2.0; - Put_Line ("2.00 (T2_D6) : " - & V_T2_D6'Image); - Put_Line ("2.00 (Int_T2_D6) : " - & V_Int_T2_D6'Image); - - Put_Line ("-----------------------------"); + + Show_Info (T0_D4'(1.0), "1.0 "); + Show_Info (T0_D4 (T2_D6'(1.55)), + "1.55 "); + Show_Info (T0_D4'(2.0), "2.0 "); + + + Show_Info (T2_D6'(1.0), "1.0 "); + Show_Info (T2_D6'(1.55), "1.55 "); + Show_Info (T2_D6'(2.0), "2.0 "); end Show_Machine_Implementation; In this example, we use the overlays :ada:`V_Int_T0_D4` and :ada:`V_Int_T2_D6` From 65fd5214fe675bca1a241c94e1beb59282b613e4 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sat, 14 Feb 2026 18:19:52 -0300 Subject: [PATCH 04/12] Add headers to code example --- content/courses/advanced-ada/parts/data_types/numerics.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index e3ce077d5..cc2f44fab 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3466,12 +3466,18 @@ machine when assigning values to objects of decimal type. For example: procedure Show_Machine_Implementation is begin + Put_Line ("============================="); + Put_Line ("T0_D4"); + Put_Line ("============================="); Show_Info (T0_D4'(1.0), "1.0 "); Show_Info (T0_D4 (T2_D6'(1.55)), "1.55 "); Show_Info (T0_D4'(2.0), "2.0 "); + Put_Line ("============================="); + Put_Line ("T2_D6"); + Put_Line ("============================="); Show_Info (T2_D6'(1.0), "1.0 "); Show_Info (T2_D6'(1.55), "1.55 "); From f6f52315e8ebca58c8fb54f71ee4c7da4ad42d41 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sat, 14 Feb 2026 18:26:27 -0300 Subject: [PATCH 05/12] Adapting explanation after changes to code example --- .../advanced-ada/parts/data_types/numerics.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index cc2f44fab..a2babc2d4 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3401,7 +3401,7 @@ the :ada:`Custom_Decimal_Types` package: end Custom_Decimal_Types; We can use an overlay to uncover the actual integer values stored on the -machine when assigning values to objects of decimal type. For example: +machine for objects of decimal type. For example: .. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types @@ -3452,6 +3452,14 @@ machine when assigning values to objects of decimal type. For example: end Custom_Decimal_Types.Show_Info_Procs; +In this example, we use the overlays :ada:`V_Int_Overlay` in the generic +procedure :ada:`Gen_Show_Info`. This allows us to retrieve the integer +representation of the decimal input variable :ada:`V`. We instantiate this +generic procedure for the :ada:`T0_D4` and :ada:`T2_D6` types (see +:ada:`Show_Info` procedures). + +We can then call :ada:`Show_Info` for a few values. By doing so, we see +the machine representation of those decimal values. For example: .. code:: ada no_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types :class: ada-run @@ -3484,11 +3492,7 @@ machine when assigning values to objects of decimal type. For example: Show_Info (T2_D6'(2.0), "2.0 "); end Show_Machine_Implementation; -In this example, we use the overlays :ada:`V_Int_T0_D4` and :ada:`V_Int_T2_D6` -to retrieve the integer representation of the decimal variables :ada:`V_T0_D4` -and :ada:`V_T2_D6`. By doing this, we retrieve the machine representation of -the real values for the :ada:`T0_D4` and :ada:`T2_D6` types. The table shows -the values that we get by running the test application: +The table shows the values that we get by running the test application: +-------------+-----------------------------+ | Real value | Integer representation | From 531bbc9a6d5108c41fe77f365b08aa8a5f1b9e51 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sat, 14 Feb 2026 18:38:59 -0300 Subject: [PATCH 06/12] Editorial change: Machine_Implementation => Machine_Representation --- .../courses/advanced-ada/parts/data_types/numerics.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index a2babc2d4..357dac883 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3377,7 +3377,7 @@ Machine representation of decimal types Let's start with decimal fixed-ppint types. Consider the following types from the :ada:`Custom_Decimal_Types` package: -.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types +.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types package Custom_Decimal_Types is @@ -3403,7 +3403,7 @@ the :ada:`Custom_Decimal_Types` package: We can use an overlay to uncover the actual integer values stored on the machine for objects of decimal type. For example: -.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types +.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types generic type T_Decimal is delta <> digits <>; @@ -3461,7 +3461,7 @@ generic procedure for the :ada:`T0_D4` and :ada:`T2_D6` types (see We can then call :ada:`Show_Info` for a few values. By doing so, we see the machine representation of those decimal values. For example: -.. code:: ada no_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Implementation_Decimal_Types +.. code:: ada no_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types :class: ada-run with Ada.Text_IO; use Ada.Text_IO; @@ -3472,7 +3472,7 @@ the machine representation of those decimal values. For example: with Custom_Decimal_Types.Show_Info_Procs; use Custom_Decimal_Types.Show_Info_Procs; - procedure Show_Machine_Implementation is + procedure Show_Machine_Representation is begin Put_Line ("============================="); Put_Line ("T0_D4"); @@ -3490,7 +3490,7 @@ the machine representation of those decimal values. For example: Show_Info (T2_D6'(1.0), "1.0 "); Show_Info (T2_D6'(1.55), "1.55 "); Show_Info (T2_D6'(2.0), "2.0 "); - end Show_Machine_Implementation; + end Show_Machine_Representation; The table shows the values that we get by running the test application: From 6f9d362dfe9239d39aba2edabbac14e6e20d034c Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 15 Feb 2026 21:26:03 -0300 Subject: [PATCH 07/12] Editorial change: correcting typo --- content/courses/advanced-ada/parts/data_types/numerics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 357dac883..1169141df 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3374,7 +3374,7 @@ retrieve the actual integer representation, we can use Machine representation of decimal types ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Let's start with decimal fixed-ppint types. Consider the following types from +Let's start with decimal fixed-point types. Consider the following types from the :ada:`Custom_Decimal_Types` package: .. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types From f2fdcaa5724937a08a3744685ff64121b0c66168 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 15 Feb 2026 21:26:31 -0300 Subject: [PATCH 08/12] Editorial change: correct button in code example --- content/courses/advanced-ada/parts/data_types/numerics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 1169141df..b8e947c52 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3403,7 +3403,7 @@ the :ada:`Custom_Decimal_Types` package: We can use an overlay to uncover the actual integer values stored on the machine for objects of decimal type. For example: -.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types +.. code:: ada no_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types generic type T_Decimal is delta <> digits <>; From 5eb930344a59d4fe6cc5eb3d8c0e9929fd3cf2c0 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 15 Feb 2026 21:26:57 -0300 Subject: [PATCH 09/12] Editorial change: adding empty line in code example --- content/courses/advanced-ada/parts/data_types/numerics.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index b8e947c52..0e4bc2aa2 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3419,6 +3419,7 @@ machine for objects of decimal type. For example: V_Int_Overlay : T_Int_Decimal with Address => V'Address, Import, Volatile; + V_Real : Float; begin V_Real := Float (V_Int_Overlay) * From 9f748d630f9d1cb22bb04954b1f2e006ec9884f3 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 15 Feb 2026 21:27:35 -0300 Subject: [PATCH 10/12] Mentioning generic procedure --- content/courses/advanced-ada/parts/data_types/numerics.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 0e4bc2aa2..fc64cf45d 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3400,8 +3400,9 @@ the :ada:`Custom_Decimal_Types` package: end Custom_Decimal_Types; -We can use an overlay to uncover the actual integer values stored on the -machine for objects of decimal type. For example: +We can use an overlay in the body of the generic :ada:`Gen_Show_Info` procedure +to uncover the actual integer values stored on the machine for objects of +decimal type. For example: .. code:: ada no_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Machine_Representation_Decimal_Types From 706332c3dc1c0f1ddf0ae891ce353e7134b40cbd Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 15 Feb 2026 21:27:54 -0300 Subject: [PATCH 11/12] Editorial change: correcting typo --- content/courses/advanced-ada/parts/data_types/numerics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index fc64cf45d..c4319aec9 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3521,7 +3521,7 @@ which, as we've seen before, is equal to the *delta* for decimal fixed-point types. (Later on, we see that this *detail* makes a difference for ordinary fixed-point types.) -For example, if we multiple the integer representation of the real value by the +For example, if we multiply the integer representation of the real value by the *small*, we get the real value: +-------------+-------------------------------+ From 6350a4c03d1aef469d4951eda7e6a15cb398fc04 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Sun, 15 Feb 2026 21:31:23 -0300 Subject: [PATCH 12/12] Editorial change: adding decimal non-exponential version of number --- content/courses/advanced-ada/parts/data_types/numerics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index c4319aec9..e3845d69a 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3183,7 +3183,7 @@ rule that it must be smaller or equal to the *delta*. For example: end Show_Fixed_Small_Delta; In this example, the *delta* that we specifed for :ada:`Ordinary_Fixed_Point` -is 0.2, while the compiler-selected *small* is 2.0\ :sup:`-3`. +is 0.2, while the compiler-selected *small* is 0.125 (2.0\ :sup:`-3`). .. admonition:: For further reading...