Skip to content

Commit 45a6e16

Browse files
authored
Merge pull request #1284 from gusthoff/content/advanced_ada/review/editorial/general/20251031/minor_improvements
Editorial changes: minor improvements to "Advanced Ada" course
2 parents c58bf9a + 3b17528 commit 45a6e16

File tree

3 files changed

+59
-44
lines changed

3 files changed

+59
-44
lines changed

content/courses/advanced-ada/parts/data_types/numeric_attributes.rst

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ universal integer value. Let's get the modulus of the 32-bit :ada:`Modular`
2424
type that we've declared in the :ada:`Num_Types` package of the previous
2525
chapter:
2626

27-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Modular_Types.Modular_1
27+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Modular_Types.Modular_1
2828

2929
package Num_Types is
3030

@@ -43,7 +43,8 @@ chapter:
4343
Put_Line (Modulus_Value'Image);
4444
end Show_Modular;
4545

46-
When we run this example, we get 4294967296, which is equal to :ada:`2**32`.
46+
When we run this example, we get 4,294,967,296 |mdash| which is equal to
47+
:ada:`2**32`.
4748

4849
:ada:`Mod` Attribute
4950
~~~~~~~~~~~~~~~~~~~~
@@ -69,7 +70,7 @@ be something like :ada:`-2**31 .. 2**31 - 1`. (Note: we discussed the
6970
Operations on modular integers use modular (wraparound) arithmetic. For
7071
example:
7172

72-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Modular_Types.Modular_1
73+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Modular_Types.Modular_1
7374

7475
with Ada.Text_IO; use Ada.Text_IO;
7576

@@ -94,7 +95,7 @@ wrap around)? The answer in Ada is the former |mdash| that is, if you try to
9495
convert, say, :ada:`Integer'(-1)` to :ada:`Modular`, you will get
9596
:ada:`Constraint_Error`:
9697

97-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Modular_Types.Modular_1
98+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Modular_Types.Modular_1
9899
:class: ada-run-expect-failure
99100

100101
with Ada.Text_IO; use Ada.Text_IO;
@@ -111,7 +112,7 @@ convert, say, :ada:`Integer'(-1)` to :ada:`Modular`, you will get
111112

112113
To solve this problem, we can use the :ada:`Mod` attribute:
113114

114-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Modular_Types.Modular_1
115+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Modular_Types.Modular_1
115116

116117
with Ada.Text_IO; use Ada.Text_IO;
117118

@@ -140,7 +141,7 @@ given modular type, using wraparound semantics.
140141
The :ada:`Mod` attribute was added to Ada 2005 to solve this problem.
141142
Also, we can now safely use this attribute in generics. For example:
142143

143-
.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Modular_Types.Mod_Attribute
144+
.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Modular_Types.Mod_Attribute
144145

145146
generic
146147
type Formal_Modular is mod <>;
@@ -180,7 +181,7 @@ performed.
180181

181182
Let's see a simple implementation of the CRC-CCITT (0x1D0F) algorithm:
182183

183-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Modular_Types.Mod_Crc_CCITT_Ada
184+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Modular_Types.Mod_Crc_CCITT_Ada
184185

185186
package Crc_Defs is
186187

@@ -298,7 +299,7 @@ Attribute: :ada:`Machine_Radix`
298299
:ada:`Machine_Radix` is an attribute that returns the radix of the hardware
299300
representation of a type. For example:
300301

301-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Machine_Radix
302+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Machine_Radix
302303

303304
with Ada.Text_IO; use Ada.Text_IO;
304305

@@ -324,7 +325,7 @@ Attributes: :ada:`Machine_Mantissa`
324325
:ada:`Machine_Mantissa` is an attribute that returns the number of bits
325326
reserved for the mantissa of the floating-point type. For example:
326327

327-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Machine_Mantissa
328+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Machine_Mantissa
328329

329330
with Ada.Text_IO; use Ada.Text_IO;
330331

@@ -352,7 +353,7 @@ and maximum value, respectively, of the machine exponent the floating-point
352353
type. Note that, in all cases, the returned value is a universal integer. For
353354
example:
354355

355-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Machine_Emin_Emax
356+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Machine_Emin_Emax
356357

357358
with Ada.Text_IO; use Ada.Text_IO;
358359

@@ -405,7 +406,7 @@ Attribute: :ada:`Digits`
405406
:ada:`Digits` is an attribute that returns the requested decimal precision of
406407
a floating-point subtype. Let's see an example:
407408

408-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Digits
409+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Digits
409410

410411
with Ada.Text_IO; use Ada.Text_IO;
411412

@@ -425,7 +426,7 @@ Note that we said that :ada:`Digits` is the *requested* level of precision,
425426
which is specified as part of declaring a floating point type. We can retrieve
426427
the actual decimal precision with :ada:`Base'Digits`. For example:
427428

428-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Base_Digits
429+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Base_Digits
429430

430431
with Ada.Text_IO; use Ada.Text_IO;
431432

@@ -462,7 +463,7 @@ indicating whether a feature is available or not in the target architecture:
462463
:ada:`Constraint_Error` exception is (or is not) guaranteed to be raised
463464
when an operation with that type produces an overflow or divide-by-zero.
464465

465-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Machine_Rounds_Overflows
466+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Machine_Rounds_Overflows
466467

467468
with Ada.Text_IO; use Ada.Text_IO;
468469

@@ -541,7 +542,7 @@ floating-point value:
541542

542543
Let's see some examples:
543544

544-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Exponent_Fraction
545+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Exponent_Fraction
545546

546547
with Ada.Text_IO; use Ada.Text_IO;
547548

@@ -600,7 +601,7 @@ Attribute: :ada:`Scaling`
600601
:ada:`Scaling` is an attribute that scales a floating-point value based on the
601602
machine radix and a machine exponent passed to the function. For example:
602603

603-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Scaling
604+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Scaling
604605

605606
with Ada.Text_IO; use Ada.Text_IO;
606607

@@ -629,7 +630,7 @@ Round-up and round-down attributes
629630
:ada:`Floor` and :ada:`Ceiling` are attributes that returned the rounded-down
630631
or rounded-up value, respectively, of a floating-point value. For example:
631632

632-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Floor_Ceiling
633+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Floor_Ceiling
633634

634635
with Ada.Text_IO; use Ada.Text_IO;
635636

@@ -655,7 +656,7 @@ is the closest integer value.
655656

656657
Let's see a code example:
657658

658-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Rounding
659+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Rounding
659660

660661
with Ada.Text_IO; use Ada.Text_IO;
661662

@@ -752,7 +753,7 @@ second parameter is the :ada:`Towards` value.
752753

753754
Let's see a code example:
754755

755-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Truncation_Remainder
756+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Truncation_Remainder
756757

757758
with Ada.Text_IO; use Ada.Text_IO;
758759

@@ -837,7 +838,7 @@ mantissa. Let's see some examples:
837838

838839
Let's see some examples:
839840

840-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Sign_Leading
841+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Sign_Leading
841842

842843
with Ada.Text_IO; use Ada.Text_IO;
843844

@@ -879,7 +880,7 @@ Not every real number is directly representable as a floating-point value on a
879880
specific machine. For example, let's take a value such as 1.0 x 10\ :sup:`15`
880881
(or 1,000,000,000,000,000):
881882

882-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Float_Value
883+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Float_Value
883884

884885
with Ada.Text_IO; use Ada.Text_IO;
885886

@@ -932,7 +933,7 @@ the difference between the original real value in our example
932933
(1.0 x 10\ :sup:`15`) and the actual value that is assigned to :ada:`V`. We can
933934
do this by using the :ada:`Machine` attribute in the calculation:
934935

935-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Machine_Attribute
936+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Machine_Attribute
936937

937938
with Ada.Text_IO; use Ada.Text_IO;
938939

@@ -1028,7 +1029,7 @@ This is the reason why we see 1.3008896 x 10\ :sup:`7` instead of
10281029

10291030
Let's see an example:
10301031

1031-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Model_Mantissa
1032+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Model_Mantissa
10321033

10331034
with Ada.Text_IO; use Ada.Text_IO;
10341035

@@ -1075,7 +1076,7 @@ This is the reason why we see 1.3008896 x 10\ :sup:`7` instead of
10751076

10761077
Let's see some examples:
10771078

1078-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Model_Epsilon_Small
1079+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Model_Epsilon_Small
10791080

10801081
with Ada.Text_IO; use Ada.Text_IO;
10811082

@@ -1118,7 +1119,7 @@ This is the reason why we see 1.3008896 x 10\ :sup:`7` instead of
11181119
value in 1.0 x 10\ :sup:`15` and the actual model value, we can use the
11191120
:ada:`Model` attribute:
11201121

1121-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Model_Attribute
1122+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Model_Attribute
11221123

11231124
with Ada.Text_IO; use Ada.Text_IO;
11241125

@@ -1169,7 +1170,7 @@ This is the reason why we see 1.3008896 x 10\ :sup:`7` instead of
11691170
Let's see a code example with these attributes and compare them to the
11701171
:ada:`First` and :ada:`Last` attributes:
11711172

1172-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Safe_First_Last
1173+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Floating_Point_Types.Safe_First_Last
11731174

11741175
with Ada.Text_IO; use Ada.Text_IO;
11751176

@@ -1229,7 +1230,7 @@ Attribute: :ada:`Machine_Radix`
12291230
:ada:`Machine_Radix` is an attribute that returns the radix of the hardware
12301231
representation of a type. For example:
12311232

1232-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Machine_Radix
1233+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Fixed_Machine_Radix
12331234

12341235
with Ada.Text_IO; use Ada.Text_IO;
12351236

@@ -1265,7 +1266,7 @@ indicating whether a feature is available or not in the target architecture:
12651266
:ada:`Constraint_Error` is guaranteed to be raised when a fixed-point
12661267
operation with that type produces an overflow or divide-by-zero.
12671268

1268-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Machine_Rounds_Overflows
1269+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Fixed_Machine_Rounds_Overflows
12691270

12701271
with Ada.Text_IO; use Ada.Text_IO;
12711272

@@ -1314,7 +1315,7 @@ it's automatically selected by the compiler, and it's always equal to the
13141315

13151316
Let's see an example:
13161317

1317-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta
1318+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Fixed_Small_Delta
13181319

13191320
package Fixed_Small_Delta is
13201321
D3 : constant := 10.0 ** (-3);
@@ -1386,7 +1387,7 @@ In the case of the :ada:`TQ15` type, we're specifying the *small* by using the
13861387
type is 32 bits, while the precision we get when operating with this type is
13871388
16 bits. Let's see a specific example for this type:
13881389

1389-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Small_Delta
1390+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Fixed_Small_Delta
13901391

13911392
with Ada.Text_IO; use Ada.Text_IO;
13921393

@@ -1431,7 +1432,7 @@ precise:
14311432

14321433
Let's see an example:
14331434

1434-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Fixed_Fore_Aft
1435+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Fixed_Fore_Aft
14351436

14361437
with Ada.Text_IO; use Ada.Text_IO;
14371438

@@ -1485,7 +1486,7 @@ use for the :ada:`digits` in the definition of a decimal fixed-point type.
14851486

14861487
Let's see an example:
14871488

1488-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Decimal_Digits
1489+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Decimal_Digits
14891490

14901491
with Ada.Text_IO; use Ada.Text_IO;
14911492

@@ -1527,7 +1528,7 @@ of :ada:`T'Scale` is three.
15271528

15281529
Let's look at this complete example:
15291530

1530-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Decimal_Scale
1531+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Decimal_Scale
15311532

15321533
with Ada.Text_IO; use Ada.Text_IO;
15331534

@@ -1570,7 +1571,7 @@ value, while the returned value is of :ada:`S'Base` type.
15701571

15711572
Let's look at this example:
15721573

1573-
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Fixed_Point_Types.Decimal_Round
1574+
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numeric_Attributes.Fixed_Point_Types.Decimal_Round
15741575

15751576
with Ada.Text_IO; use Ada.Text_IO;
15761577

content/courses/advanced-ada/parts/data_types/numerics.rst

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ In this example, we get a compilation error because the range of the
785785
.. admonition:: For further reading...
786786

787787
To circumvent the compilation error in the code example we've just seen,
788-
the best alternative to use :ref:`big numbers <Adv_Ada_Big_Numbers>`
788+
the best alternative is to use :ref:`big numbers <Adv_Ada_Big_Numbers>`
789789
|mdash| we discuss this topic later on in this chapter:
790790

791791
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Universal_Numeric_Types.Conversion_To_Non_Universal_Types switches=Compiler(-gnat2022);
@@ -2315,7 +2315,7 @@ As expected, we can derive from any floating-point type. For example:
23152315
with Ada.Text_IO; use Ada.Text_IO;
23162316

23172317
with Custom_Floating_Point_Types;
2318-
use Custom_Floating_Point_Types;
2318+
use Custom_Floating_Point_Types;
23192319

23202320
procedure Show_Derived_Floating_Point_Types is
23212321
C : Coefficient;
@@ -2463,9 +2463,7 @@ still select a 32-bit floating-point type for the target platform. For example:
24632463

24642464
.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Floating_Point_Types.Floating_Point_Decimal_Precision
24652465

2466-
with Ada.Text_IO; use Ada.Text_IO;
2467-
2468-
procedure Show_Decimal_Digits is
2466+
package Custom_Floating_Point_Types is
24692467

24702468
type Float_1_Digits is
24712469
digits 1;
@@ -2503,6 +2501,15 @@ still select a 32-bit floating-point type for the target platform. For example:
25032501
digits 17;
25042502
type Float_18_Digits is
25052503
digits 18;
2504+
2505+
end Custom_Floating_Point_Types;
2506+
2507+
with Ada.Text_IO; use Ada.Text_IO;
2508+
2509+
with Custom_Floating_Point_Types;
2510+
use Custom_Floating_Point_Types;
2511+
2512+
procedure Show_Decimal_Digits is
25062513
begin
25072514
Put_Line ("Float_1_Digits'Size :"
25082515
& Float_1_Digits'Size'Image
@@ -2577,6 +2584,10 @@ floating-point data types on the target hardware. However, as you might recall
25772584
from an earlier chapter, we can request specific sizes for custom types. We
25782585
discuss this topic next.
25792586

2587+
Note that, for the example above, the size of the type is equal to the size of
2588+
its base type, i.e. :ada:`Float_1_Digits'Size = Float_1_Digits'Base'Size`,
2589+
:ada:`Float_2_Digits'Size = Float_2_Digits'Base'Size`, and so on.
2590+
25802591

25812592
.. _Adv_Ada_Floating_Point_Type_Size:
25822593

@@ -2613,6 +2624,9 @@ bits to be represented |mdash| instead of the 32 bits that we would typically
26132624
see on a desktop PC. (Also, remember that this code example won't compile if
26142625
your target architecture doesn't support 128-bit floating-point data types.)
26152626

2627+
.. todo::
2628+
2629+
Discuss :ada:`Float_6_Digits'Size` vs. :ada:`Float_6_Digits'Base'Size`.
26162630

26172631

26182632
Range of custom floating-point types and subtypes
@@ -3363,7 +3377,7 @@ it's always equal to the *delta*.
33633377
For example, we may define a normalized range between -1.0 and 1.0 as
33643378
following:
33653379

3366-
.. code:: ada run_button project=Courses.Intro_To_Ada.Fixed_Point_Types.Normalized_Fixed_Point_Type
3380+
.. code:: ada run_button project=Courses.Advanced_Ada.Fixed_Point_Types.Normalized_Fixed_Point_Type
33673381

33683382
with Ada.Text_IO; use Ada.Text_IO;
33693383

@@ -3390,7 +3404,7 @@ it's always equal to the *delta*.
33903404

33913405
We may also rewrite this code with an exact type definition:
33923406

3393-
.. code:: ada compile_button project=Courses.Intro_To_Ada.Fixed_Point_Types.Normalized_Adapted_Fixed_Point_Type
3407+
.. code:: ada compile_button project=Courses.Advanced_Ada.Fixed_Point_Types.Normalized_Adapted_Fixed_Point_Type
33943408

33953409
procedure Normalized_Adapted_Fixed_Point_Type is
33963410
type TQ31 is
@@ -3402,7 +3416,7 @@ it's always equal to the *delta*.
34023416

34033417
We may also use any other range. For example:
34043418

3405-
.. code:: ada run_button project=Courses.Intro_To_Ada.Fixed_Point_Types.Custom_Fixed_Point_Range
3419+
.. code:: ada run_button project=Courses.Advanced_Ada.Fixed_Point_Types.Custom_Fixed_Point_Range
34063420

34073421
with Ada.Text_IO; use Ada.Text_IO;
34083422
with Ada.Numerics; use Ada.Numerics;
@@ -3431,7 +3445,7 @@ it's always equal to the *delta*.
34313445

34323446
All standard operations are available for fixed-point types. For example:
34333447

3434-
.. code:: ada run_button project=Courses.Intro_To_Ada.Fixed_Point_Types.Fixed_Point_Op
3448+
.. code:: ada run_button project=Courses.Advanced_Ada.Fixed_Point_Types.Fixed_Point_Op
34353449

34363450
with Ada.Text_IO; use Ada.Text_IO;
34373451

0 commit comments

Comments
 (0)