-
Notifications
You must be signed in to change notification settings - Fork 41
Adding section about decimal fixed-point types #1293
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
base: main
Are you sure you want to change the base?
Adding section about decimal fixed-point types #1293
Conversation
swbaird
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff! I raised a few points.
| integer types to emulate fixed-point operations. | ||
|
|
||
| As mentioned in the Introduction to Ada course course, fixed-point types | ||
| are classified in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "are classified as either blah or blah". This use of "in" seems odd.
| the compiler to derive a range. | ||
|
|
||
| .. code-block:: ada | ||
| Note that, unlike floating-point types, there are no predefined decimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "unlike floating-point types and ordinary fixed-point types" ? Feel free to ignore this suggestion.
| zero. For example: | ||
|
|
||
| .. code:: ada run_button project=Courses.Intro_To_Ada.Fixed_Point_Types.Decimal_Fixed_Point_Smaller | ||
| The *delta* is a scaling factor (a power of ten) that allows developers to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to mention here the fact that delta = small for a decimal fixed point type (unlike the case of an ordinary fixed point type)? I think that would be worth noting somewhere in this document (perhaps not here).
|
|
||
| with Ada.Text_IO; use Ada.Text_IO; | ||
| Let's look at a small, practical example showing the conversion between two | ||
| currencies |mdash| in this case, between euros and yens: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plural of "yen" is "yen", not "yens".
|
|
||
| -- Exchange rates as of | ||
| -- 2025-12-26: | ||
| EUR_Yen : constant := 184.365_5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps EUR_Per_Yen and Yen_Per_EUR ?
| floating-point type :ada:`TD18`. Conversion between these two types works as | ||
| expected: we use :ada:`TD18 (D6)` to convert from a decimal fixed-point type | ||
| and :ada:`T2_D6 (D18)` to convert to a decimal fixed-point type. Of course, | ||
| when converting to a decimal fixed-point type, we have to ensure that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are talking about two forms of conversions (both float-to-decimal-fixed and the reverse) and, having established that context, we then make it sound like a range check on the result is only performed in one of the two cases. That seems at least confusing. Consider
type Flo is new Float range 0.0 .. 1234.5;
type Dfx is delta 1.0 digits 5;
Dfx_Obj : Dft := -1.0;
Flo_Obj : Flo := Flo (Dfx_Obj); -- fails range check
| & Max_Delta'Image); | ||
| end Show_Min_Max_Scale; | ||
|
|
||
| On a desktop PC, you may see that the :ada:`Min_Scale` is -38, while the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps "On a 64-bit desktop PC"?
| & Max_Decimal_Digits'Image); | ||
| end Show_Max_Decimal_Digits; | ||
|
|
||
| On a typical desktop PC, we may see that the value of :ada:`Max_Decimal_Digits` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for previous "desktop PC" reference.
|
|
||
| .. admonition:: For further reading... | ||
|
|
||
| The :ada:`Digits` attribute gives us the number of significant decimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere in this document, it might be worth mentioning that attributes like Digits, Delta, and Scale can be usefully applied to a generic formal decimal fixed point type. They are not just for retrieving information that could be obtained equally well (at the cost of some redundancy in the code) by looking at the type declaration. Or perhaps such formal types are beyond the scope of this document?
|
|
||
| In this example, the :ada:`Max_Fin_Decimal` type uses a delta of 0.01 and the | ||
| number of significant decimal digits based on the value of | ||
| :ada:`Max_Decimal_Digits`. On a typical desktop PC, this gives us (almost) a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same "desktop PC" comment as before - if I encounter "desktop PC" again later in this review, I won't bother flagging it.
No description provided.