@@ -1876,31 +1876,60 @@ There are many attributes on modular types. We talk about them
1876
1876
- :arm22: `3.5.4 Integer Types <3-5-4> `
1877
1877
1878
1878
1879
- .. todo : :
1879
+ .. _ Adv_Ada_System_Max_Modulus :
1880
1880
1881
- - Add subsection: "Binary and nonbinary modulus"
1881
+ System max. values for modulus
1882
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1882
1883
1883
- - Discuss: :ada: `System.Max_Binary_Modulus ` and
1884
- :ada: `System.Max_Nonbinary_Modulus `
1884
+ When we use a power-of-two number as the modulus, the maximum value that we
1885
+ could use in the type declaration is indicated by the
1886
+ :ada: `System.Max_Binary_Modulus ` constant. In contrast, for non-power-of-two
1887
+ numbers, the maximum value for the modulus is indicated by the
1888
+ :ada: `System.Max_Nonbinary_Modulus ` constant:
1885
1889
1886
- - Circumvent `Constraint_Error ` for `System.Max_Binary_Modulus ` in the
1887
- :ada: `Show_Max_Binary_Nonbinary_Modulus ` procedure below!
1890
+ .. code :: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Discrete_Numeric_Types.Max_Binary_Nonbinary_Modulus_Values
1888
1891
1889
- .. code :: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Discrete_Numeric_Types.Max_Binary_Nonbinary_Modulus
1890
- :class: ada-run-expect-failure
1892
+ with System;
1893
+ with Ada.Text_IO; use Ada.Text_IO;
1891
1894
1892
- with System;
1893
- with Ada.Text_IO; use Ada.Text_IO;
1895
+ procedure Show_Max_Binary_Nonbinary_Modulus is
1896
+ type Modular_Max is
1897
+ mod System.Max_Binary_Modulus;
1898
+ begin
1899
+ Put_Line
1900
+ ("System.Max_Binary_Modulus - 1 :"
1901
+ & Modular_Max'Last'Image);
1902
+ Put_Line
1903
+ ("System.Max_Nonbinary_Modulus :"
1904
+ & System.Max_Nonbinary_Modulus'Image);
1905
+ end Show_Max_Binary_Nonbinary_Modulus;
1894
1906
1895
- procedure Show_Max_Binary_Nonbinary_Modulus is
1896
- begin
1897
- Put_Line
1898
- ("System.Max_Binary_Modulus :"
1899
- & System.Max_Binary_Modulus'Image);
1900
- Put_Line
1901
- ("System.Max_Nonbinary_Modulus :"
1902
- & System.Max_Nonbinary_Modulus'Image);
1903
- end Show_Max_Binary_Nonbinary_Modulus;
1907
+ On a typical desktop PC, you might get the following values:
1908
+
1909
+ - :ada: `System.Max_Binary_Modulus `: 2\ :sup: `128` =
1910
+ 340,282,366,920,938,463,463,374,607,431,768,211,456
1911
+
1912
+ - :ada: `System.Max_Nonbinary_Modulus `: 2\ :sup: `32` - 1 = 4,294,967,295
1913
+
1914
+ As expected, we can simply use these constants in modular type declarations:
1915
+
1916
+ .. code :: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Discrete_Numeric_Types.Max_Binary_Nonbinary_Modulus_Types
1917
+
1918
+ with System;
1919
+
1920
+ package Show_Max_Binary_Nonbinary_Modulus is
1921
+
1922
+ type Modular_Max is
1923
+ mod System.Max_Binary_Modulus;
1924
+
1925
+ type Modular_Max_Non_Power_Two is
1926
+ mod System.Max_Nonbinary_Modulus;
1927
+
1928
+ end Show_Max_Binary_Nonbinary_Modulus;
1929
+
1930
+ In this example, we use :ada: `Max_Binary_Modulus ` as the modulus of the
1931
+ :ada: `Modular_Max ` type, and :ada: `Max_Nonbinary_Modulus ` as the modulus of the
1932
+ :ada: `Modular_Max_Non_Power_Two ` type.
1904
1933
1905
1934
1906
1935
0 commit comments