From: | "Dann Corbit" <DCorbit(at)connx(dot)com> |
---|---|
To: | <map(at)inter-resa(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: float formating with xx.00 |
Date: | 2003-07-04 01:14:33 |
Message-ID: | D90A5A6C612A39408103E6ECDD77B829408B5E@voyager.corporate.connx.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
/*
**
** Not a surprise, to them that knows:
**
*/
#include <stdio.h>
#include <stdlib.h>
#define A_LEN 500
static float foo[A_LEN];
static double bar[A_LEN];
int
main (void)
{
long i;
double d;
float f;
for (i = 0; i < A_LEN; i++)
{
d = rand () / (rand () + 1.0);
d *= d;
if (rand () % 2)
d = -d;
foo[i] = (float) d;
bar[i] = d;
}
f = 0;
d = 0;
for (i = 0; i < A_LEN; i++)
{
f += foo[i];
d += bar[i];
}
printf ("forward float sum = %.20f\n", f);
printf ("forward double sum = %.20f\n", d);
f = 0;
d = 0;
for (i = A_LEN - 1; i >= 0; i--)
{
f += foo[i];
d += bar[i];
}
printf ("backward float sum = %.20f\n", f);
printf ("backward double sum = %.20f\n", d);
return 0;
}
/*
OpenVMS VAX:
$ run foo
forward float sum = -6724682.50000000000000000000
forward double sum = -6724682.13690311496610000000
backward float sum = -6724679.50000000000000000000
backward double sum = -6724682.13690311496610000000
OpenVMS Alpha:
$ run foo
forward float sum = -6724682.50000000000000000000
forward double sum = -6724682.13690311090000000000
backward float sum = -6724679.50000000000000000000
backward double sum = -6724682.13690311370000000000
$
GCC on AMD Athlon:
$ ./a
forward float sum = -56051.43860578643943881616
forward double sum = -56051.43626179593411507085
backward float sum = -56051.43860578643943881616
backward double sum = -56051.43626179593411507085
MS VC++ 6 on AMD Athlon with /Ox flag:
C:\tmp>foo
forward float sum = 545785.98050410976000000000
forward double sum = 545786.01145155274000000000
backward float sum = 545785.98050410964000000000
backward double sum = 545786.01145155251000000000
MS VC++ 6 on AMD Athlon with /Op flag (forces memory storage):
C:\tmp>foo
forward float sum = 545785.93750000000000000000
forward double sum = 545786.01145155274000000000
backward float sum = 545785.56250000000000000000
backward double sum = 545786.01145155251000000000
*/
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-07-04 01:32:47 | Re: float formating with xx.00 |
Previous Message | Dann Corbit | 2003-07-04 01:07:27 | Re: float formating with xx.00 |