Skip to content

Extending section on fixed-point types#1317

Open
gusthoff wants to merge 16 commits intoAdaCore:mainfrom
gusthoff:content/advanced_ada/new_content/numerics/fixed_point_types/20260215
Open

Extending section on fixed-point types#1317
gusthoff wants to merge 16 commits intoAdaCore:mainfrom
gusthoff:content/advanced_ada/new_content/numerics/fixed_point_types/20260215

Conversation

@gusthoff
Copy link
Collaborator

  • Adding subsections on ordinary fixed-point types.
  • Adding subsection on type conversions and machine representation.
  • Adding subsection on integer multiplication and division.

@gusthoff gusthoff added the new section Section using new content label Feb 16, 2026
@gusthoff gusthoff force-pushed the content/advanced_ada/new_content/numerics/fixed_point_types/20260215 branch from c5abbcb to 96719a8 Compare February 16, 2026 03:38
@gusthoff gusthoff force-pushed the content/advanced_ada/new_content/numerics/fixed_point_types/20260215 branch from 96719a8 to 021a0a2 Compare March 15, 2026 17:36
@gusthoff gusthoff force-pushed the content/advanced_ada/new_content/numerics/fixed_point_types/20260215 branch from 021a0a2 to defd5b3 Compare March 20, 2026 14:48
@gusthoff gusthoff requested a review from swbaird March 20, 2026 14:48
Copy link

@swbaird swbaird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of good stuff here.
I've got a few comments.

:ada:`Decimal` type.

Let's now focus on subtypes of ordinary fixed-point types:

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The immediately preceding line says we are about to declare a subtype of a Decimal type.

delta D
range -1.0 .. 1.0 - D;

subtype Coefficient is Short_Fixed;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impose a constraint? For the derived type example, we declared a derived type that agreed with its parent type with respect to constraints (and predicates). We don't need to illustrate all possible combinations, but perhaps we should mix it up a little. Add some case where "X in Short_Fixed" yields True and "X in Coefficient" yields False? Feel free to ignore this suggestion - there are always more cases that could be described and we have to draw the line somewhere.

is
V_Local : T_Fixed;

V_Int_Overlay : T_Int_Fixed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, do we want an assertion that the size and/or alignments match for an overlay?


package Angles is

D : constant := 0.2;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment emphasizing that D is not an exact power of two? Maybe not.

range -2 ** (Angle'Size - 1) ..
2 ** (Angle'Size - 1) - 1;

type Angle_Adj is
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a comment that Angle'Small /= Angle'Delta, while Angle_Adj'Small = Angle_Adj'Delta? Maybe not if this point (i.e. if not explicitly specified, then Small is a power of two) is already covered elsewhere.

Here, we write :ada:`TQ31 (V_15)` to convert the value of :ada:`V_15` from the
:ada:`TQ15` to the :ada:`TQ31` type. Likewise, we write :ada:`TQ15 (V_31)` to
convert the value of :ada:`V_31` from the :ada:`TQ31` to the :ada:`TQ15` type.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show the output generated by Show_Fixed_Point_Conversions? This is like reading a mystery novel and then finding that the last chapter is missing!

[A digression:
I don't know if you want to get into it, but a type conversion whose operand is a call to a universal-fixed-valued operator is an interesting beast. It is essentially all one operation. Usually a type conversion proceeds in two steps: evaluate the operand (ignoring the fact that it is the operand of a type conversion) and then perform the conversion. But in this universal-fixed case, it is all rolled into one. In a case like
Fx1 (Fx2'(X) * Fx3'(Y))
where there are 3 different fixed point types, the result depends on the 3 different Small values (one for each of the fixed point types) as well as the integer values of X and Y.]

generic
type T_Decimal is delta <> digits <>;
procedure Gen_Show_Decimal_Type_Info
(Dummy : T_Decimal;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why Dummy? And yet again below.

test application:

+--------+-----------------------------------+-----------------------------------+
| Real | Original / source | Target |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"real" vs. "actual" seems like an unclear distinction. Perhaps "mathematically exact" vs. "exactly representable", or something like that.

| 225.00 | :ada:`T2_D6` | 22500 | 225.0 | :ada:`T2_D12` | 22500 | 225.0 |
+--------+---------------+---------+---------+---------------+---------+---------+

As expected, when converting to a type with less accuracy |mdash| i.e. whose
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is correct to says that a fixed point type with a smaller Small is more accurate than one with a larger Small, but it still seems like it might be confusing. Would it be too pedantic to point out that it is possible for a particular value to be exactly representable in the "less precise" representation but not in the "more precise" representation? If so, then feel free to ignore this comment.

with Angles.Show_Info_Procs;
use Angles.Show_Info_Procs;

procedure Show_Machine_Representation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a duplicate of a version of Show_Machine_Representation that was declared earlier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new section Section using new content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants