From f8abc5ff2142125db10db5d3f1352108050f149e Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 22 Aug 2025 20:35:16 +0200 Subject: [PATCH 1/9] Editorial change: remove todo item --- .../courses/advanced-ada/parts/data_types/numerics.rst | 9 +++------ 1 file changed, 3 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 dd39224e6..87d90eb66 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3008,16 +3008,13 @@ decimal precision greater than the maximum supported precision. Therefore, compilation fails for this example. -.. :: +.. _Adv_Ada_Fixed_Point_Types: - .. _Adv_Ada_Fixed_Point_Types: +Fixed-point types +----------------- - Fixed-point types - ----------------- - .. todo:: - Complete section! .. :: From 488d2956c80169d5b65283d77e00c692ae9331ed Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 5 Sep 2025 20:41:52 +0200 Subject: [PATCH 2/9] Editorial change: adding subsection --- content/courses/advanced-ada/parts/data_types/numerics.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 87d90eb66..4aa68703c 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3016,6 +3016,11 @@ Fixed-point types +.. _Adv_Ada_Fixed_Point_Types_Small_Delta: + +Small and delta +~~~~~~~~~~~~~~~ + .. :: From fa06d5c4edcc0c3f491e706c042d8e49927cd811 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 5 Sep 2025 20:47:21 +0200 Subject: [PATCH 3/9] Editorial change: moving parts of subsection on Small and Delta attributes --- .../parts/data_types/numeric_attributes.rst | 57 -------------- .../parts/data_types/numerics.rst | 77 +++++++++++++++++++ 2 files changed, 77 insertions(+), 57 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst b/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst index a50b223d4..1dec156b0 100644 --- a/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst +++ b/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst @@ -1295,63 +1295,6 @@ type :ada:`T` is equal to the :ada:`Delta` of that type |mdash| i.e. :ada:`T'Small = T'Delta`. Let's discuss each attribute and how they distinguish from each other. -The :ada:`Delta` attribute returns the value of the :ada:`delta` that was -used in the type definition. For example, if we declare -:ada:`type T3_D3 is delta 10.0 ** (-3) digits D`, then the value of -:ada:`T3_D3'Delta` is the :ada:`10.0 ** (-3)` that we used in the type -definition. - -The :ada:`Small` attribute returns the "small" of a type, i.e. the smallest -value used in the machine representation of the type. The *small* must be at -least equal to or smaller than the *delta* |mdash| in other words, it must -conform to the :ada:`T'Small <= T'Delta` rule. - -.. admonition:: For further reading... - - The :ada:`Small` and the :ada:`Delta` need not actually be small numbers. - They can be arbitrarily large. For instance, they could be 1.0, or 1000.0. - Consider the following example: - - .. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Large_Small_Attribute - - package Fixed_Point_Defs is - S : constant := 32; - Exp : constant := 128; - D : constant := 2.0 ** (-S + Exp + 1); - - type Fixed is delta D - range -1.0 * 2.0 ** Exp .. - 1.0 * 2.0 ** Exp - D; - - pragma Assert (Fixed'Size = S); - end Fixed_Point_Defs; - - with Fixed_Point_Defs; use Fixed_Point_Defs; - with Ada.Text_IO; use Ada.Text_IO; - - procedure Show_Fixed_Type_Info is - begin - Put_Line ("Size : " - & Fixed'Size'Image); - Put_Line ("Small : " - & Fixed'Small'Image); - Put_Line ("Delta : " - & Fixed'Delta'Image); - Put_Line ("First : " - & Fixed'First'Image); - Put_Line ("Last : " - & Fixed'Last'Image); - end Show_Fixed_Type_Info; - - In this example, the *small* of the :ada:`Fixed` type is actually quite - large: 1.58456325028528675\ :sup:`29`. (Also, the first and the last values - are large: -340,282,366,920,938,463,463,374,607,431,768,211,456.0 and - 340,282,366,762,482,138,434,845,932,244,680,310,784.0, or approximately - -3.4028\ :sup:`38` and 3.4028\ :sup:`38`.) - - In this case, if we assign 1 or 1,000 to a variable :ada:`F` of this type, - the actual value stored in :ada:`F` is zero. Feel free to try this out! - When we declare an ordinary fixed-point data type, we must specify the *delta*. Specifying the *small*, however, is optional: diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 4aa68703c..4c3511e00 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3021,6 +3021,83 @@ Fixed-point types Small and delta ~~~~~~~~~~~~~~~ +The :ada:`Small` and :ada:`Delta` attributes return numbers that indicate the +numeric precision of a fixed-point type. In many cases, the :ada:`Small` of a +type :ada:`T` is equal to the :ada:`Delta` of that type |mdash| i.e. +:ada:`T'Small = T'Delta`. Let's discuss each attribute and how they distinguish +from each other. + +The :ada:`Delta` attribute returns the value of the :ada:`delta` that was +used in the type definition. For example, if we declare +:ada:`type T3_D3 is delta 10.0 ** (-3) digits D`, then the value of +:ada:`T3_D3'Delta` is the :ada:`10.0 ** (-3)` that we used in the type +definition. + +The :ada:`Small` attribute returns the "small" of a type, i.e. the smallest +value used in the machine representation of the type. The *small* must be at +least equal to or smaller than the *delta* |mdash| in other words, it must +conform to the :ada:`T'Small <= T'Delta` rule. + +.. admonition:: For further reading... + + The :ada:`Small` and the :ada:`Delta` need not actually be small numbers. + They can be arbitrarily large. For instance, they could be 1.0, or 1000.0. + Consider the following example: + + .. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Large_Small_Attribute + + package Fixed_Point_Defs is + S : constant := 32; + Exp : constant := 128; + D : constant := 2.0 ** (-S + Exp + 1); + + type Fixed is delta D + range -1.0 * 2.0 ** Exp .. + 1.0 * 2.0 ** Exp - D; + + pragma Assert (Fixed'Size = S); + end Fixed_Point_Defs; + + with Fixed_Point_Defs; use Fixed_Point_Defs; + with Ada.Text_IO; use Ada.Text_IO; + + procedure Show_Fixed_Type_Info is + begin + Put_Line ("Size : " + & Fixed'Size'Image); + Put_Line ("Small : " + & Fixed'Small'Image); + Put_Line ("Delta : " + & Fixed'Delta'Image); + Put_Line ("First : " + & Fixed'First'Image); + Put_Line ("Last : " + & Fixed'Last'Image); + end Show_Fixed_Type_Info; + + In this example, the *small* of the :ada:`Fixed` type is actually quite + large: 1.58456325028528675\ :sup:`29`. (Also, the first and the last values + are large: -340,282,366,920,938,463,463,374,607,431,768,211,456.0 and + 340,282,366,762,482,138,434,845,932,244,680,310,784.0, or approximately + -3.4028\ :sup:`38` and 3.4028\ :sup:`38`.) + + In this case, if we assign 1 or 1,000 to a variable :ada:`F` of this type, + the actual value stored in :ada:`F` is zero. Feel free to try this out! + +When we declare an ordinary fixed-point data type, we must specify the *delta*. +Specifying the *small*, however, is optional: + +- If the *small* isn't specified, it is automatically selected by the compiler. + In this case, the actual value of the *small* is an implementation-defined + power of two |mdash| always following the rule that says: + :ada:`T'Small <= T'Delta`. + +- If we want, however, to specify the *small*, we can do that by using the + :ada:`Small` aspect. In this case, it doesn't need to be a power of two. + +For decimal fixed-point types, we cannot specify the *small*. In this case, +it's automatically selected by the compiler, and it's always equal to the +*delta*. .. :: From 9a4fe9cd2873ae1a449a715521bbc6f8c76e5755 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 5 Sep 2025 20:48:05 +0200 Subject: [PATCH 4/9] Editorial change: adding anchor --- .../advanced-ada/parts/data_types/numeric_attributes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst b/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst index 1dec156b0..6638b00a6 100644 --- a/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst +++ b/content/courses/advanced-ada/parts/data_types/numeric_attributes.rst @@ -1286,6 +1286,8 @@ indicating whether a feature is available or not in the target architecture: end Show_Boolean_Attributes; +.. _Adv_Ada_Fixed_Point_Type_Small_Delta_Attributes: + Attribute: :ada:`Small` and :ada:`Delta` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 14e2d1581552072b9bf7dcea0d703023ac858842 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 5 Sep 2025 22:05:11 +0200 Subject: [PATCH 5/9] Adding subsection on small and delta of fixed-point types --- .../parts/data_types/numerics.rst | 107 ++++++++++++++---- 1 file changed, 82 insertions(+), 25 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 4c3511e00..966b988a7 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3021,26 +3021,58 @@ Fixed-point types Small and delta ~~~~~~~~~~~~~~~ -The :ada:`Small` and :ada:`Delta` attributes return numbers that indicate the -numeric precision of a fixed-point type. In many cases, the :ada:`Small` of a -type :ada:`T` is equal to the :ada:`Delta` of that type |mdash| i.e. -:ada:`T'Small = T'Delta`. Let's discuss each attribute and how they distinguish +The *small* and the *delta* of a fixed-point type indicate the numeric +precision of that type. Let's discuss these concepts and how they distinguish from each other. -The :ada:`Delta` attribute returns the value of the :ada:`delta` that was -used in the type definition. For example, if we declare -:ada:`type T3_D3 is delta 10.0 ** (-3) digits D`, then the value of -:ada:`T3_D3'Delta` is the :ada:`10.0 ** (-3)` that we used in the type -definition. +The *delta* corresponds to the value used for the :ada:`delta` in the type +definition. For example, if we declare +:ada:`type T3_D3 is delta 10.0 ** (-3) digits D`, then the *delta* is equal to +the 10.0\ :sup:`-3` that we used in the type definition. + +The *small* of a type :ada:`T` is the smallest positive value used in the +machine representation of the type. In other words, while the *delta* is +primarily a user-selected value that (ideally) fits the requirements of the +implementation, the *small* indicates how that *delta* is represented on the +target machine. + +The *small* must be at least equal to or smaller than the *delta*. In many +cases, however, the *small* of a type :ada:`T` is equal to the *delta* of that +type. In addition, note that these values aren't necessarily small numbers +|mdash| in fact, they could be quite large. + +We can use the :ada:`T'Small` and :ada:`T'Delta` attributes to retrieve the +actual values of the *small* and *delta* of a fixed-point type :ada:`T`. (We +discuss more details about these attributes +:ref:`in another chapter `.) +For example: + +.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta + + with Ada.Text_IO; use Ada.Text_IO; + + procedure Show_Fixed_Small_Delta is -The :ada:`Small` attribute returns the "small" of a type, i.e. the smallest -value used in the machine representation of the type. The *small* must be at -least equal to or smaller than the *delta* |mdash| in other words, it must -conform to the :ada:`T'Small <= T'Delta` rule. + type Ordinary_Fixed_Point is + delta 0.25 + range -2.0 .. 2.0; + + begin + Put_Line ("Ordinary_Fixed_Point'Small: " + & Ordinary_Fixed_Point'Small'Image); + Put_Line ("Ordinary_Fixed_Point'Delta: " + & Ordinary_Fixed_Point'Delta'Image); + Put_Line ("Ordinary_Fixed_Point'Size: " + & Ordinary_Fixed_Point'Size'Image); + end Show_Fixed_Small_Delta; + +In this example, we see the values for the compiler-selected *small* and the +*delta* of type :ada:`Ordinary_Fixed_Point`. (Both are 0.25.) .. admonition:: For further reading... - The :ada:`Small` and the :ada:`Delta` need not actually be small numbers. + As we've just mentioned, the small and the delta need not actually be small + numbers. They can be arbitrarily large. For instance, they could be 1.0, or 1000.0. Consider the following example: @@ -3084,20 +3116,45 @@ conform to the :ada:`T'Small <= T'Delta` rule. In this case, if we assign 1 or 1,000 to a variable :ada:`F` of this type, the actual value stored in :ada:`F` is zero. Feel free to try this out! -When we declare an ordinary fixed-point data type, we must specify the *delta*. -Specifying the *small*, however, is optional: +When we declare a fixed-point data type, we must specify the *delta*. In +contrast, providing a *small* in the type declaration is optional. If we want +to specify the *small*, we can use the :ada:`Small` aspect. (We'll see this +aspect again later on.) +However, we can only do so for ordinary fixed-point types: for decimal +fixed-point types, the *small* is automatically selected by the compiler, and +it's always equal to the *delta*. + +When the *small* isn't specified, it is automatically selected by the compiler. +In this case, the actual value of the *small* is an implementation-defined +power of ten for decimal fixed-point types and a power of two for ordinary +fixed-point types. Again, the selected value always follows the rule that says +that the *small* is smaller or equal to the delta. For example: + +.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta + + with Ada.Text_IO; use Ada.Text_IO; + + procedure Show_Fixed_Small_Delta is + + type Ordinary_Fixed_Point is + delta 0.2 + range -2.0 .. 2.0; + + begin + Put_Line ("Ordinary_Fixed_Point'Small: " + & Ordinary_Fixed_Point'Small'Image); + Put_Line ("Ordinary_Fixed_Point'Delta: " + & Ordinary_Fixed_Point'Delta'Image); + Put_Line ("Ordinary_Fixed_Point'Size: " + & Ordinary_Fixed_Point'Size'Image); + 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`. + -- If the *small* isn't specified, it is automatically selected by the compiler. - In this case, the actual value of the *small* is an implementation-defined - power of two |mdash| always following the rule that says: - :ada:`T'Small <= T'Delta`. -- If we want, however, to specify the *small*, we can do that by using the - :ada:`Small` aspect. In this case, it doesn't need to be a power of two. -For decimal fixed-point types, we cannot specify the *small*. In this case, -it's automatically selected by the compiler, and it's always equal to the -*delta*. .. :: From 6765e565377feabf1a7dea0e3713e8b4dafc7358 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 5 Sep 2025 22:08:34 +0200 Subject: [PATCH 6/9] Editorial change: moving admonition further down --- .../parts/data_types/numerics.rst | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 966b988a7..19febff02 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3069,9 +3069,45 @@ For example: In this example, we see the values for the compiler-selected *small* and the *delta* of type :ada:`Ordinary_Fixed_Point`. (Both are 0.25.) +When we declare a fixed-point data type, we must specify the *delta*. In +contrast, providing a *small* in the type declaration is optional. If we want +to specify the *small*, we can use the :ada:`Small` aspect. (We'll see this +aspect again later on.) +However, we can only do so for ordinary fixed-point types: for decimal +fixed-point types, the *small* is automatically selected by the compiler, and +it's always equal to the *delta*. + +When the *small* isn't specified, it is automatically selected by the compiler. +In this case, the actual value of the *small* is an implementation-defined +power of ten for decimal fixed-point types and a power of two for ordinary +fixed-point types. Again, the selected value always follows the rule that says +that the *small* is smaller or equal to the delta. For example: + +.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta + + with Ada.Text_IO; use Ada.Text_IO; + + procedure Show_Fixed_Small_Delta is + + type Ordinary_Fixed_Point is + delta 0.2 + range -2.0 .. 2.0; + + begin + Put_Line ("Ordinary_Fixed_Point'Small: " + & Ordinary_Fixed_Point'Small'Image); + Put_Line ("Ordinary_Fixed_Point'Delta: " + & Ordinary_Fixed_Point'Delta'Image); + Put_Line ("Ordinary_Fixed_Point'Size: " + & Ordinary_Fixed_Point'Size'Image); + 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`. + .. admonition:: For further reading... - As we've just mentioned, the small and the delta need not actually be small + As we've mentioned, the small and the delta need not actually be small numbers. They can be arbitrarily large. For instance, they could be 1.0, or 1000.0. Consider the following example: @@ -3116,42 +3152,6 @@ In this example, we see the values for the compiler-selected *small* and the In this case, if we assign 1 or 1,000 to a variable :ada:`F` of this type, the actual value stored in :ada:`F` is zero. Feel free to try this out! -When we declare a fixed-point data type, we must specify the *delta*. In -contrast, providing a *small* in the type declaration is optional. If we want -to specify the *small*, we can use the :ada:`Small` aspect. (We'll see this -aspect again later on.) -However, we can only do so for ordinary fixed-point types: for decimal -fixed-point types, the *small* is automatically selected by the compiler, and -it's always equal to the *delta*. - -When the *small* isn't specified, it is automatically selected by the compiler. -In this case, the actual value of the *small* is an implementation-defined -power of ten for decimal fixed-point types and a power of two for ordinary -fixed-point types. Again, the selected value always follows the rule that says -that the *small* is smaller or equal to the delta. For example: - -.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta - - with Ada.Text_IO; use Ada.Text_IO; - - procedure Show_Fixed_Small_Delta is - - type Ordinary_Fixed_Point is - delta 0.2 - range -2.0 .. 2.0; - - begin - Put_Line ("Ordinary_Fixed_Point'Small: " - & Ordinary_Fixed_Point'Small'Image); - Put_Line ("Ordinary_Fixed_Point'Delta: " - & Ordinary_Fixed_Point'Delta'Image); - Put_Line ("Ordinary_Fixed_Point'Size: " - & Ordinary_Fixed_Point'Size'Image); - 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`. - From 309f91e1e7685e3976d7ec3bbddf9032d52ba19c Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 3 Oct 2025 21:50:01 +0200 Subject: [PATCH 7/9] Editorial changes: rearranging paragraphs --- .../parts/data_types/numerics.rst | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index 19febff02..a3eeae742 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3070,18 +3070,13 @@ In this example, we see the values for the compiler-selected *small* and the *delta* of type :ada:`Ordinary_Fixed_Point`. (Both are 0.25.) When we declare a fixed-point data type, we must specify the *delta*. In -contrast, providing a *small* in the type declaration is optional. If we want -to specify the *small*, we can use the :ada:`Small` aspect. (We'll see this -aspect again later on.) -However, we can only do so for ordinary fixed-point types: for decimal -fixed-point types, the *small* is automatically selected by the compiler, and -it's always equal to the *delta*. +contrast, providing a *small* in the type declaration is optional. When the *small* isn't specified, it is automatically selected by the compiler. In this case, the actual value of the *small* is an implementation-defined power of ten for decimal fixed-point types and a power of two for ordinary -fixed-point types. Again, the selected value always follows the rule that says -that the *small* is smaller or equal to the delta. For example: +fixed-point types. Again, the selected value always follows the rule that the +*small* must be smaller or equal to the delta. For example: .. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta @@ -3105,6 +3100,17 @@ that the *small* is smaller or equal to the delta. For example: 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`. +If we want to specify the *small*, we can use the :ada:`Small` aspect. (we'll +see this aspect again later on.) + +.. todo:: + + Add link to subsection on :ada:`Small` aspect once available. + +However, we can only do so for ordinary fixed-point types: for decimal +fixed-point types, the *small* is automatically selected by the compiler, and +it's always equal to the *delta*. + .. admonition:: For further reading... As we've mentioned, the small and the delta need not actually be small From 6433f5829a60365835154252a9c2f9bc2638c4fd Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 3 Oct 2025 21:52:18 +0200 Subject: [PATCH 8/9] Editorial change: adding anchor --- content/courses/intro-to-ada/chapters/fixed_point_types.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/courses/intro-to-ada/chapters/fixed_point_types.rst b/content/courses/intro-to-ada/chapters/fixed_point_types.rst index 2e50fcbe6..baea4003d 100644 --- a/content/courses/intro-to-ada/chapters/fixed_point_types.rst +++ b/content/courses/intro-to-ada/chapters/fixed_point_types.rst @@ -1,3 +1,5 @@ +.. _Intro_Ada_Fixed_Point_Types: + Fixed-point types ================= From 4faf4fd40f06eee730a1896124c4de758e3cd51b Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 3 Oct 2025 21:55:25 +0200 Subject: [PATCH 9/9] Adding small introduction to fixed-point types --- .../parts/data_types/numerics.rst | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/content/courses/advanced-ada/parts/data_types/numerics.rst b/content/courses/advanced-ada/parts/data_types/numerics.rst index a3eeae742..e7a17e799 100644 --- a/content/courses/advanced-ada/parts/data_types/numerics.rst +++ b/content/courses/advanced-ada/parts/data_types/numerics.rst @@ -3013,7 +3013,63 @@ compilation fails for this example. Fixed-point types ----------------- +We already discussed :ref:`fixed-point types ` in +the Introduction to Ada course. Roughly speaking, fixed-point types can be +thought as a way to mimic operations that look like floating-point types, but +use discrete numeric types *in the background*. This has a big advantage for +the implementation of certain numeric algorithms, as developers can use +operations that look familiar because they resemble the ones they use with +floating-point types. +.. admonition:: In other languages + + In many programming languages such as C, there's no built-in support for + fixed-point types. This forces developers that need fixed-point types to + circumvent this absence with sometimes cumbersome alternative. They could, + for example, use integer types and introduce additional operations to match + fixed-point operations. Alternatively, frameworks or non-portable, + compiler-specific extensions might be used in some cases. In contrast, the + fact that Ada has built-in support for fixed-point types means that using + these types is both portable and doesn't require extra efforts to + circumvent limitations |mdash| such as the ones that originate from using + integer types to emulate fixed-point operations. + +As mentioned in the Introduction to Ada course course, fixed-point types +are classified in +decimal fixed-point types and +ordinary (binary). + +.. todo:: + + Add link to sections above once available. + +Decimal fixed-point types are based on power of tens and have the following +syntax: + +.. code-block:: ada + + type is + delta digits ; + +Decimal fixed-point types are useful, for example, in many financial +applications, where round-off errors from arithmetic operations are considered +unacceptable. + +Ordinary fixed-point types are based on power of twos (in their hardware +implementation) and have the following syntax: + +.. code-block:: ada + + type is + delta + range .. ; + +Ordinary fixed-point types can be found for example in some implementations for +digital signal processing. + +In the next sections, we discuss further details about these specific types. +Next in this section, we introduce the concept of *small* and *delta* of +fixed-point types, which are common for both kinds of fixed-point types. .. _Adv_Ada_Fixed_Point_Types_Small_Delta: