[Discuss] IEEE doubles

pw p.willis at telus.net
Tue Jun 26 07:11:12 PDT 2007


Daniel M German wrote:
> 
> Hi Alan,
> 
> I was curious, so I ran your program in both PowerPC and Intel. In the
> PowerPC it generated:
> 
>    1.00000e-200    1.00000e+250     0.00000e+00 
>     0  
>     0  
>            -inf 
> ----------------------------------------------------------------------
> In Intel:
> 
>    1.00000e-200    1.00000e+250     0.00000e+00 
>     1  
>     0  
>            -inf 
> ----------------------------------------------------------------------
> My gut feeling was that the reason was the optimization done by the
> compiler. So I added a new variable (temp) and then rerun it.  See
> the code below. It generates the expected output. In a nutshell, the
> compiler realizes that the division can be converted into a
> multiplication, which is faster to evaluate (at least in an Intel
> instruction set). It is a matter of disassembling the code to make
> sure this is exactly what is happening. 
> 
> 
> [dmg at ti tmp]$ ./rip 
>    1.00000e-200    1.00000e+250     0.00000e+00 
> 1>    1  
> 2>    0  
>     0  
>            -inf 
> ----------------------------------------------------------------------
> 

The powerpc results are quite telling.

This is why I have been looking at compiler flags for intel
to see if there is a way to turn this optimization off.

As a side note, I have run into similar types of behavior in intel based
programs ported from sparc, PPC, 68000, where float, double and int
are mixed with the assumption
that compilation will make adequate type conversions for you.
As a habit I tend to stick to one type until I really require a
type conversion, and then check to make sure that rounding, underflow,
overflow, aren't causing any funny results.

One more thing to put on the checklist I guess.

Peter


More information about the Discuss mailing list