This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Floating poing 'non-bug'? Or is this a bug?
- From: "Yuval Kfir" <yuvalk at mainsoft dot com>
- To: <gcc at gcc dot gnu dot org>
- Cc: <segher at kernel dot crashing dot org>
- Date: Tue, 6 Jul 2004 14:34:09 +0300
- Subject: Re: Floating poing 'non-bug'? Or is this a bug?
- Organization: Mainsoft Corporation Ltd.
Segher Boessenkool wrote:
> No. Just like in the other case, i gets converted to a double,
> multiplied, and converted to an integer. By pure luck in the
> other case the temporary result (before conversion back to integer)
> is a bit over 6.0; in this case, it obviously is smaller than 6.0 .
>
> You might want to use a different rounding method than truncate-to-zero.
It's not exactly 'pure luck'. The assembly file shows the following
instructions are used in the calculcation involving a double variable:
movl $5, -4(%ebp)
fildl -4(%ebp)
fldl .LC0
fmulp %st, %st(1)
fstpl -16(%ebp)
fldl -16(%ebp)
fnstcw -18(%ebp)
movw -18(%ebp), %ax
When storing the calculation in an 'int', the fstpl, fldl instructions do
not appear. I don't know what these instructions do, but obviously they are
responsible for the 'extra rounding' that takes effect here...?
Is all of this compatible with the C standard?
- Yuval
P.S. please CC me on the replies, I am not subscribed to gcc@gcc.gnu.org.
Thank you!