|
|
Larry I Smith wrote:
Pavel Pokorny wrote:
Dear gcc friends,
can you, please, help me
to use a 16 byte long double precision (35 decimal digits)?
It looks like a 10 byte (18 digits) precision
on my AMD Opteron hp xw9300 workstation
although sizeof reports 16 bytes!
#include<stdio.h>
int main()
{
int i;
long double x,dx=0.1,x0=2;
for (i=1;i<20;i++){
dx = dx/10;
x = x0 + dx;
x = x - x0;
(void) printf ("i=%d x=%LG\n",i,x);
};
(void) printf (" sizeof(x) = %d \n", (int)sizeof(x));
}
i=1 x=0.01
i=2 x=0.001
i=3 x=0.0001
i=4 x=1E-05
i=5 x=1E-06
i=6 x=1E-07
i=7 x=1E-08
i=8 x=1E-09
i=9 x=1E-10
i=10 x=1E-11
i=11 x=1E-12
i=12 x=1E-13
i=13 x=1E-14
i=14 x=1.00007E-15
i=15 x=9.99634E-17
i=16 x=9.97466E-18
i=17 x=1.0842E-18
i=18 x=0
i=19 x=0
sizeof(x) = 16
gcc (GCC) 3.4.4 20050721 (Red Hat 3.4.4-2)
Linux 2.6.9-22.EL #1 Mon Sep 19 17:49:49 EDT 2005 x86_64 x86_64 x86_64
Thanks for any advice.
If the precision is not specified in the printf format string,
then it defaults to 6; see 'man -S3 printf' for details.
For example, to get a precision of 30 use "%.30LG", e.g.:
printf ("i=%d x=%.30LG\n",i,x);
Apart from that: In <float.h>, the numerical limits introduced
by the C Standard are specified. So, you can ask for the number
of mantissa bits, effective decimal digits etc.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
|
|