[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-11 23:32:02
Message-ID: 200401120032.02805.joachim.eibl () gmx ! de
[Download RAW message or body]
> #include <stdio.h>
> int main()
> {
> long double a=49.84;
> long double b=33.52;
> long double c=a+b;
> printf("%2.2llf + %2.2llf = %2.14llf\n",a,b,c);
> }
This little program contains a little surprise because you assign a double
constant to a long double variable.
Check this on your machine.
long double a=49.84; // double constant
printf("%2.30llf\n",a); // 49.840000000000003410605131648481
long double a1=49.84L; // long double constant
printf("%2.30llf\n",a1); // 49.840000000000000000138777878078
This just illustrates how tricky it can be.
BTW: There is no real general solution. You might just settle for a compromise
like showing fewer digits. But it won't help you when you start subtracting
almost equal numbers like: 1000.0000 - 1000.0001 etc.
Cheers,
Joachim
>> 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