> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 24, 1999 6:58 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Float -> Double conversion bug ?
>
>
> Dear all,
>
> If I try to put a float into a double variable the last bits of the
> precision are total garbage ! If I try to put the float 0.3 into the a
> double the result is 0.30000001192092896 !!! This could be a 'feature'
> but it renders java (or at least jdk1.2) completely useless
> for numerics
> !
This most likely has nothing to do with the Java implementation, but of the
floating point characteristics of the underlying machine. If you set a
double (in C) to 0.3, it's value is not necessarily 0.3 but something very
very close:
#include <stdio.h>
int
main()
{
float f = 3.3;
double d = 3.3;
printf("%f\n", d );
printf("%40.30f\n", f ); // This float will be converted to double
printf("%40.30f\n", d );
return 0;
}
This program returns the following on a PII running Linux:
3.300000
3.299999952316284179687500000000
3.299999999999999822364316059975
On an RS6000 running AIX:
3.300000
3.299999952316284179687500000000
3.299999999999999822364316059970
-K
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]