[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Open Bugs in 3.2
From: Joachim Eibl <joachim.eibl () gmx ! de>
Date: 2004-01-12 7:27:12
Message-ID: 200401120827.13050.joachim.eibl () gmx ! de
[Download RAW message or body]
Just another thought: When dealing with floating point numbers, we should use
a floating point representation ("%g"). Not assuming fixed point ("%f").
That's where the trouble starts, because big numbers have fever valid digits
after the comma.
See the program below, followed by its output.
Cheers,
Joachim
/* /usr/lib/gcc-lib/i586-suse-linux/3.3.1/include/float.h */
#include <float.h>
#include <stdio.h>
#include <math.h>
int main()
{
long double a = 0.0001L; // 0.0001
long double b = 1000.0001L; // 100.0001
long double c = b - 1000.0L - a; // 0
printf("%2.30Lf\n",a);
printf("%2.30Lf\n",b);
printf("%2.30Lf\n",c);
printf("\n");
printf("%*.*Lg\n", LDBL_DIG+8, LDBL_DIG, a);
printf("%*.*Lg\n", LDBL_DIG+8, LDBL_DIG, b);
printf("%*.*Lg\n", LDBL_DIG+8, LDBL_DIG, c);
}
Output on my machine:
0.000100000000000000000001143494
1000.000099999999999988986587595718
-0.000000000000000011013413547776
0.0001
1000.0001
-1.10134135477760317e-17
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic