[Bug ada/41675] GNAT rejects type with 64 bits, claiming it has 65 bits
--- Comment #2 from dirk dot herrmann-privat at gmx dot de 2009-12-05 11:25 --- Hello, thanks for considering the bug. I checked that the maximum value that could be stored in scalars of type T would be 0xFF80. Thus, a representation within 64 bits is possible. I have also taken a look at the AARM, where in section 13.3 "Operational and Representation Attributes" (http://www.adaic.com/standards/1zaarm/html/AA-13-3.html) paragraphs 54 and 55 it says: 54 {recommended level of support (Size attribute) [partial]} The recommended level of support for the Size attribute of subtypes is: 55 * The Size (if not specified) of a static discrete or fixed point subtype should be the number of bits needed to represent each value belonging to the subtype using an unbiased representation, leaving space for a sign bit only if the subtype contains negative values. If such a subtype is a first subtype, then an implementation should support a specified Size for it that reflects this representation. So, it may not be a bug, but as I understand it, it would at least be against the recommendation from the AARM. Best regards, Dirk -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41675
[Bug ada/41675] New: GNAT rejects type with 64 bits, claiming it has 65 bits
Hello everybody, the following piece of code demonstrates the problem. It compiles and prints out "T'Size: 63". Thus, with the commented line used instead, the result should be "T'Size: 64". But in that case GNAT terminates with the following error message: "main.adb:5:04: size required (65) for type "t" too large, maximum allowed is 64". with Ada.Text_IO; procedure Main is -- T_Delta : constant := 0.1 * (2.0**(-64 + 9)); -- Gnat bug T_Delta : constant := 0.1 * (2.0**(-63 + 9)); type T is delta T_Delta range 0.0 .. 51.1; for T'Small use T_Delta; begin Ada.Text_IO.Put_Line("T'Size: " & Integer'Image(T'Size)); end Main; One possible reason is, that GNAT counts a sign bit, which is not counted when the 'Size attribute is queried. In any case, I assume that this inconsistency is unintended. Here's the versions that I am using: > gnatmake --version GNATMAKE 4.3.4 ... > gcc -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.4-2' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.3.4 (Debian 4.3.4-2) Friendly regards, Dirk Herrmann -- Summary: GNAT rejects type with 64 bits, claiming it has 65 bits Product: gcc Version: 4.3.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dirk dot herrmann-privat at gmx dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41675
[Bug ada/41416] Conversion Float to fixed-point behaves differently for static expressions
--- Comment #2 from dirk dot herrmann-privat at gmx dot de 2009-10-05 16:48 --- Hi, thanks for considering my report. The relevant sections seem to be (these were pointed out to me on comp.lang.ada by Adam Beneschan): 4.9(38) : "For a real static expression that is not part of a larger static expression ... 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...". 4.9(38.1/2): "The rounding of static floating point expressions is implementation-defined. It is recommended that the rounding be the same as the default rounding on the target system." A.5.4(3): S'Machine_Rounds: Yields the value True if rounding is performed on inexact results of every predefined operation that yields a result of the type T; yields the value False otherwise. The value of this attribute is of the predefined type Boolean. Here's the interpretation (for which I also used some input from comp.lang.ada by Adam Beneschan): 4.9(38) demands rounding or truncation for real static expressions, depending on the value of Machine_Rounds. A.5.4(3) is not limited to static expressions, but relates "Machine_Rounds = True" to rounding. The behaviour in case of "Machine_Rounds = False" is left open by A.5.4(3), though. The implementation advice in 4.9(38.1/2) recommends that static rounding should be the same as the default rounding. There is no explicit statement with respect to how non-static expressions should be handled in case of "Machine_Rounds = False". But, 4.9(38.1/2) can be interpreted such that it is generally desired that static and non-static behaviour should match. Therefore: 4.9(38) demands truncation for static expressions in case of "Machine_Rounds = False", and it seems plausible to me that this should then also apply for non-static expressions. Thanks again, Dirk -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41416
[Bug ada/41416] New: Conversion Float to fixed-point behaves differently for static expressions
Hi, the following complete sample code shows different conversion behaviours between fixed-point types and Float to fixed-point depending on whether the expressions are static or not. In the static case, GNAT uses a conversion strategy comparable to truncation, otherwise rounding is used. I assume that this difference in behaviour is unintended. --- start --- with Ada.Text_IO; use Ada.Text_IO; procedure Conversion is type FpA is delta 0.5 range -10.0 .. +10.0; for FpA'Small use 0.5; type FpB is delta 0.4 range -10.0 .. +10.0; for FpB'Small use 0.4; function MakeB(F: in Float) return FpB is begin return FpB(F); end MakeB; function MakeBFromA(F: in FpA) return FpB is begin return FpB(F); end MakeBFromA; function MakeBViaA(F: in Float) return FpB is begin return FpB(FpA(F)); end MakeBViaA; function Get_Minus_1_5 return Float is begin return -1.5; end Get_Minus_1_5; begin Put_Line(FpA'Image(FpA(-1.5))); Put_Line( FpB'Image(FpB(-1.5)) & " " --> -1.2 (truncation) & FpB'Image(FpB(Float(-1.5))) & " " --> -1.2 (truncation) & FpB'Image(FpB(Get_Minus_1_5)) & " "--> -1.6 (rounding) & FpB'Image(MakeB(-1.5))); --> -1.6 (rounding) Put_Line( FpB'Image(FpB(FpA(-1.5))) & " " --> -1.2 (truncation) & FpB'Image(FpB(FpA(Float(-1.5 & " " --> -1.2 (truncation) & FpB'Image(FpB(FpA'Succ(FpA(-2.0 & " " --> -1.2 (truncation) & FpB'Image(FpB(FpA(Get_Minus_1_5))) & " " --> -1.6 (rounding) & FpB'Image(MakeBFromA(FpA(-1.5))) & " " --> -1.6 (rounding) & FpB'Image(MakeBViaA(-1.5))); --> -1.6 (rounding) end Conversion; end The command line I am using for building: > gnatmake -f -gnatVa -gnata -gnatwadhl.o -O3 -save-temps conversion.adb The output from GNAT: --- start --- conversion.adb:35:17: warning: static fixed-point value is not a multiple of Small conversion.adb:36:19: warning: static fixed-point value is not a multiple of Small conversion.adb:40:17: warning: static fixed-point value is not a multiple of Small conversion.adb:41:19: warning: static fixed-point value is not a multiple of Small conversion.adb:42:19: warning: static fixed-point value is not a multiple of Small gnatbind -x conversion.ali gnatlink conversion.ali end The version of GNAT I am using: > gcc -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.4-2' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.3.4 (Debian 4.3.4-2) Friendly regards, Dirk Herrmann -- Summary: Conversion Float to fixed-point behaves differently for static expressions Product: gcc Version: 4.3.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dirk dot herrmann-privat at gmx dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41416