From: J.H.Kim on
Hi, everyone

My java compiler and interpreter cannot display floating point variable.

public class PrintTest {
public static void main(String[] args) {
double a = 3.141592;
System.out.println(a);
}
}

The routine above does not display 3.141592.

My compiler version is

frog1120:/home/frog/Java/Work/012# javac -version
Eclipse Java Compiler v_774_R33x, 3.3.1, Copyright IBM Corp 2000, 2007.

and interpreter version is

frog1120:/home/frog/Java/Work/012# java -version
java version "1.5.0"
gij (GNU libgcj) version 4.3.2
Copyright (C) 2007 Free Software Foundation, Inc.


Please give me a hint for this problem.


p.s) My system is debian linux and when I installed eclipse,
the development tools are installed, too. But now I want to unistall the
java development tools of eclipse. So, I did it, but the java tools of
eclipse is not installed.
When I overwrite sun java packages, the java tools of eclipse remains.
How can I uninstall the java tools for eclipse completely?


Thanks in advance

Best Regards,
J.Hwan Kim
From: markspace on
J.H.Kim wrote:
> Hi, everyone
>
> My java compiler and interpreter cannot display floating point variable.
>
> public class PrintTest {
> public static void main(String[] args) {
> double a = 3.141592;
> System.out.println(a);
> }
> }
>
> The routine above does not display 3.141592.

<http://docs.sun.com/source/806-3568/ncg_goldberg.html>

Floating point numbers aren't exact. You can't get exactly 3.141592 out
of any floating point system. Consider using BigDecimal if you need
"exact" numbers.
From: Screamin Lord Byron on
On 07/12/2010 05:15 PM, markspace wrote:
> J.H.Kim wrote:
>> Hi, everyone
>>
>> My java compiler and interpreter cannot display floating point variable.
>>
>> public class PrintTest {
>> public static void main(String[] args) {
>> double a = 3.141592;
>> System.out.println(a);
>> }
>> }
>>
>> The routine above does not display 3.141592.
>
> <http://docs.sun.com/source/806-3568/ncg_goldberg.html>
>
> Floating point numbers aren't exact. You can't get exactly 3.141592 out
> of any floating point system. Consider using BigDecimal if you need
> "exact" numbers.


Well, in this example there is no calculation, and significand fits
within 52 bits of IEEE 754 double type so it should be printed out as
expected: 3.141592. Please someone correct me if I'm wrong.

However, OP forgot to mention what actually is displayed after running this.
From: rossum on
On Tue, 13 Jul 2010 00:07:36 +0900, "J.H.Kim" <frog1120(a)gmail.com>
wrote:

>My java compiler and interpreter cannot display floating point variable.
>
>public class PrintTest {
> public static void main(String[] args) {
> double a = 3.141592;
> System.out.println(a);
> }
> }
>
>The routine above does not display 3.141592.
What does it display?

rossum

From: markspace on
Screamin Lord Byron wrote:

> Well, in this example there is no calculation, and significand fits
> within 52 bits of IEEE 754 double type so it should be printed out as
> expected: 3.141592. Please someone correct me if I'm wrong.
>
> However, OP forgot to mention what actually is displayed after running this.


You're right, it prints correctly on my system. I assumed that the OP
had run afoul of some infinitely repeating decimal/binary problem.
Since everything I've heard about gij suggests it's just plain broken, I
now assume the problem must be there.

The OP should try an up-to-date JVM from Sun.