!standard 04.09 (38) 04-03-23 AI95-00100/04 !class confirmation 99-03-21 !status ARG Approved 9-0-0 04-03-05 !status work item 95-10-21 !status received 95-10-12 !priority Low !difficulty Medium !subject Truncation required for static expressions if Machine_Rounds is False !summary A static expression of a fixed or floating point type that is not part of a larger static expression will be rounded or truncated based on the value of Machine_Rounds for the type. !question Is the intent of 4.9(38) to require truncation for values of static expressions if Machine_Rounds is false? (Yes.) !response Paragraph 4.9(38) reads: "For a real static expression that is not part of a larger static expression, and whose expected type is not a descendent of a formal scalar type, the implementation shall round or truncate the value (according to the Machine_Rounds attribute of the expected type) to the nearest machine number of the expected type; if the value is exactly half-way between two machine numbers, any rounding shall be performed away from zero. If the expected type is a descendant of a formal scalar type, no special rounding or truncating is required--normal accuracy rules apply (see Annex G)." Reading just the first sentence may be confusing, but the second sentence makes the intent clear: there are special rounding and truncation rules that only apply to static scalar expressions which are not descended from a formal scalar type. To do this correctly will require special effort, but this effort is required in any case since the legality rules require this evaluation to be done without Overflow_Checks. In other words this evaluation in general cannot be done using normal machine arithmetic. !appendix !section 4.9(38) !subject Truncation required if Machine_Rounds false? !reference RM95-4.9(38), RM95-A.5.3(11) !from Jim Ledger 95-10-09 <> !discussion The following portion of 4.9(38) can be interpreted to mean that, for a real static expression that is not part of a larger static expression, if Machine_Rounds is false for the expected type, the implementation *must* truncate the value to the nearest machine number: For a real static expression that is not part of a larger static expression, and whose expected type is not a descendant of a formal scalar type, THE IMPLEMENTATION SHALL ROUND OR TRUNCATE THE VALUE (ACCORDING TO THE MACHINE_ROUNDS ATTRIBUTE OF THE EXPECTED TYPE) to the nearest machine number of the expected type..." However, A.5.3(11) says that T'Machine_Rounds is true if rounding is performed on inexact results of every predefined operation yielding a result of type T, and is false otherwise. The implication here is that if Machine_Rounds is false, the implementation *may* but need not truncate the value. Is the intent of 4.9(38) to *require* truncation for values of static expressions if Machine_Rounds is false? Furthermore, I presume (based on e-mail from Tucker Taft in another forum) that 4.9(38) is intended to apply to fixed point expected types as well as floating point, even though the concept of "machine numbers" is not defined for fixed point types. That is, one can substitute "integral multiple of the small" for "machine number" in 4.9(38) to get the corresponding rule for fixed point types. Is truncation (to a multiple of small) *required* if the expected type is ordinary fixed point and Machine_Rounds is false? What about decimal fixed point? The issue for fixed point types is clouded by AARM 4.9(38.d), which implies that truncation is mandated for static conversion to a fixed point type or division by integer. I don't see why truncation (regardless of the value of Machine_Rounds) should be required in all cases, and only for these two operations. When this paragraph says "...must do truncation..." should it have said "...must do truncation or rounding...?" Jim Ledger ACVC Team jim@sis.saic.com **************************************************************** !section 4.9(38) !subject Truncation required if Machine_Rounds false? !reference RM95-4.9(38), RM95-A.5.3(11) !reference 95-5320.a Jim Ledger 95-10-10 !from Ted Baker95-10-11 <> !discussion | The issue for fixed point types is clouded by AARM 4.9(38.d), which implies | that truncation is mandated for static conversion to a fixed point type or | division by integer. I don't see why truncation (regardless of the value of | Machine_Rounds) should be required in all cases, and only for these two | operations. When this paragraph says "...must do truncation..." should it | have said "...must do truncation or rounding...?" There is one important reason for requiring truncation for fixed-point arithmetic. The type Duration is fixed-point. Real-time programs sometimes need to do potentially inexact computations with Duration, such as division to convert between a rate and a period, or multiplication of a period times an interation count. With truncation, the error introduced by such computations can be analyzed precisely, and compensation can be made for cumulative errors. On the other hand, with rounding, it does not just require more complex computations, but the direction of single-bit rounding is not predictable (could round up or down). The issue is especially important for static expressions, because of the case of task periods (or other time intervals) that are specified by constants that cannot be represented exactly in binary, like 0.001. We need to know what Duration(0.001) means. --Ted Baker **************************************************************** !section 4.9(38) !subject Truncation required if Machine_Rounds false? !reference RM95-4.9(38), RM95-A.5.3(11) !reference 95-5320.a Jim Ledger 95-10-10 !reference as: 95-5323.a Ted Baker 95-10-11 !from Robert Dewar 95-10-11 !reference as: 95-5330.a Robert Dewar 95-10-12>> !discussion I am surprised that people are seriously considering the possibility of requiring truncation for (non-decimal) fixed-point. If the RM says this, it is an unintentional consequence that the ARG should fix. The intention is that fixed-point semantics in Ada 95 be essentially identical to those in Ada 83, expect for relaxing some accuracy requirements. We certainly do NOT want to *add* accuracy requirements. The idea of existing Ada 83 implementations having to go to lots of effort to adjust their existing implementation of ordinary fixed-point is an unacceptable one. Fixed-point is simply not important enough to be worth a major incompatible change (incompatible in the implementation sense, rather than the formal semantic sense). **************************************************************** !section 4.9(38) !subject Truncation required if Machine_Rounds false? !reference RM95-4.9(38), RM95-A.5.3(11) !reference 95-5320.a Jim Ledger 95-10-10 !from Jim Ledger 95-10-12 !reference 95-5337.a Jim Ledger 95-10-13>> !discussion > There is one important reason for requiring truncation for > fixed-point arithmetic. The type Duration is fixed-point. > Real-time programs sometimes need to do potentially inexact > computations with Duration, such as division to convert between a > rate and a period, or multiplication of a period times an > interation count. With truncation, the error introduced by such > computations can be analyzed precisely, and compensation can be > made for cumulative errors. On the other hand, with rounding, it > does not just require more complex computations, but the direction > of single-bit rounding is not predictable (could round up or > down). > > The issue is especially important for static expressions, because > of the case of task periods (or other time intervals) that are > specified by constants that cannot be represented exactly in > binary, like 0.001. We need to know what Duration(0.001) means. > > --Ted Baker That all sounds reasonable, but does 4.9(38) actually require such truncation? If so, is it only required if Machine_Rounds is false? Is it required for decimal as well as ordinary fixed point types? Is it required for floating point types as well (when Machine_Rounds is false)? Jim Ledger ACVC Team jim@sis.saic.com **************************************************************** !section 4.9(38) !subject Truncation required if Machine_Rounds false? !reference RM95-4.9(38), RM95-A.5.3(11) !reference 95-5320.a Jim Ledger 95-10-10 !reference as: 95-5323.a Ted Baker 95-10-11 !reference 95-5330.a Robert Dewar 95-10-12 !from Ted Baker 95-10-13 !reference 95-5338.a Ted Baker 95-10-13>> !discussion | I am surprised that people are seriously considering the possibility of | requiring truncation for (non-decimal) fixed-point. If the RM says this, | it is an unintentional consequence that the ARG should fix. You should not be surprised, and it is intentional, since we had a rather lengthy discussion of it at a WG9 meeting in Boston. --Ted Baker **************************************************************** Editor's note: The priority of this AI was changed based on ARG discussion in November 2000. ****************************************************************