[Discuss] IEEE doubles
Daniel M German
dmgerman at uvic.ca
Mon Jun 25 21:41:36 PDT 2007
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
----------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
int main(void)
{
double x=1.e-200, xscale=1.e+250;
double y;
double temp;
int greater;
printf("%15.5e %15.5e %15.5e \n", x, xscale, x/xscale);
greater = x/xscale > 0.e0;
printf("1>%5i \n", greater);
temp = x/xscale;
greater = temp > 0.e0;
printf("2>%5i \n", greater);
greater = x/xscale > 1.e-305;
printf("%5i \n", greater);
y = log(x/xscale);
printf("%15.5e \n", y);
return(0);
}
--
--
Daniel M. German
http://turingmachine.org/
http://silvernegative.com/
dmg (at) uvic (dot) ca
replace (at) with @ and (dot) with .
More information about the Discuss
mailing list