public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/41416] New: Conversion Float to fixed-point behaves differently for static expressions
@ 2009-09-20 14:04 dirk dot herrmann-privat at gmx dot de
2009-10-03 11:43 ` [Bug ada/41416] " sam at gcc dot gnu dot org
2009-10-05 16:48 ` dirk dot herrmann-privat at gmx dot de
0 siblings, 2 replies; 3+ messages in thread
From: dirk dot herrmann-privat at gmx dot de @ 2009-09-20 14:04 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug ada/41416] Conversion Float to fixed-point behaves differently for static expressions
2009-09-20 14:04 [Bug ada/41416] New: Conversion Float to fixed-point behaves differently for static expressions dirk dot herrmann-privat at gmx dot de
@ 2009-10-03 11:43 ` sam at gcc dot gnu dot org
2009-10-05 16:48 ` dirk dot herrmann-privat at gmx dot de
1 sibling, 0 replies; 3+ messages in thread
From: sam at gcc dot gnu dot org @ 2009-10-03 11:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from sam at gcc dot gnu dot org 2009-10-03 11:43 -------
It would help if you provided the RM reference that you think is violated here.
--
sam at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |sam at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41416
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug ada/41416] Conversion Float to fixed-point behaves differently for static expressions
2009-09-20 14:04 [Bug ada/41416] New: Conversion Float to fixed-point behaves differently for static expressions dirk dot herrmann-privat at gmx dot de
2009-10-03 11:43 ` [Bug ada/41416] " sam at gcc dot gnu dot org
@ 2009-10-05 16:48 ` dirk dot herrmann-privat at gmx dot de
1 sibling, 0 replies; 3+ messages in thread
From: dirk dot herrmann-privat at gmx dot de @ 2009-10-05 16:48 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-10-05 16:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-20 14:04 [Bug ada/41416] New: Conversion Float to fixed-point behaves differently for static expressions dirk dot herrmann-privat at gmx dot de
2009-10-03 11:43 ` [Bug ada/41416] " sam at gcc dot gnu dot org
2009-10-05 16:48 ` dirk dot herrmann-privat at gmx dot de
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).