This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Floating poing 'non-bug'? Or is this a bug?


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!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]