Skip to content

Adding small section on real numeric types #1250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 86 additions & 6 deletions content/courses/advanced-ada/parts/data_types/numerics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1346,20 +1346,100 @@ of the program before it's adapted to fit the constraints of the
- Standard types vs. compiler-specific types
- e.g.: `Integer` vs. `Long_Long_Integer`


.. _Adv_Ada_Real_Numeric_Types:

Real Numeric Types
------------------

In the Introduction to Ada course, we talked about
:ref:`floating-point <Intro_Ada_Floating_Point_Types>` and
:doc:`fixed-point </courses/intro-to-ada/chapters/fixed_point_types>` types.
In Ada, these two categories of numeric types belong to the so-called *real
types*. In very simple terms, we could say that real types are the ones whose
objects we could assign
:ref:`real numeric literals <Adv_Ada_Numeric_Literals>` to. For example:

.. code:: ada run_button project=Courses.Advanced_Ada.Data_Types.Numerics.Real_Numeric_Types.Universal_And_Real_Numeric_Types

procedure Show_Real_Numeric_Object is
V : Float;
begin
V := 2.3333333333;
-- ^^^^^^^^^^^^
-- real numeric literal
end Show_Real_Numeric_Object;

Note that we shouldn't confuse real numeric types with
:ref:`universal real types <Adv_Ada_Universal_Real_Integer>`. Even though we
can assign a named number of universal real type to an object of a real type,
these terms refer to very distinct concepts. For example:

.. code:: ada compile_button project=Courses.Advanced_Ada.Data_Types.Numerics.Real_Numeric_Types.Universal_And_Real_Numeric_Types

package Universal_And_Real_Numeric_Types is

Pi : constant := 3.1415926535;
-- ^^^^^^^^^^^^
-- universal real type

V : Float := Pi;
-- ^^^^^
-- real type
-- (floating-point type)
--

end Universal_And_Real_Numeric_Types;

In this example, :ada:`Pi` is a named number of universal real type, while
:ada:`V` is an object of real type |mdash| and of floating-point type, to be
more precise.

Note that both real types and universal real types are implicitly derived from
the :ref:`root real type <Adv_Ada_Root_Types>`, which we already discussed in
another chapter.

In the next two sections, we discuss further details about
floating-point and
fixed-point types.

.. todo::

Add link to section on floating-point types <Adv_Ada_Floating_Point_Types>
when it has become available!

.. todo::

Add link to section on fixed-point types <Adv_Ada_Fixed_Point_Types>
when it has become available!

.. admonition:: In the Ada Reference Manual

- :arm22:`3.5.6 Real Types <3-5-6>`


.. ::

.. _Adv_Ada_Real_Numeric_Types:
.. _Adv_Ada_Floating_Point_Types:

Real Numeric Types
------------------
Floating-point types
--------------------

.. todo::

Complete section!

- Recap of real numeric types
- Floating-point types
- Fixed-point types

.. ::

.. _Adv_Ada_Fixed_Point_Types:

Fixed-point types
-----------------

.. todo::

Complete section!


.. _Adv_Ada_Big_Numbers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ used to define the standard Boolean type:
As mentioned previously, every "built-in" type in Ada is defined with facilities
generally available to the user.


.. _Intro_Ada_Floating_Point_Types:

Floating-point types
--------------------

Expand Down
Loading