For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2008 > classpath-0.92+floats+patch+arm









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author classpath-0.92+floats+patch+arm
grp62

2008-03-04, 7:26 pm

Hello,
I encountered some problems when i tried to use the float type on my
embedded board based on arm926ejs core.
Indeed with the following code:
/
****************************************
********************************/
public class helloworld{
public static void main(String argv[]){
double dvar = 0.1;
float fvar = 0.1f;
System.out.println("Hello\n");
System.out.println("\nboth of these should be 0.1:");
System.out.println("double var = " + dvar);
System.out.println("float var = " + fvar);

System.out.println("\ndouble size = " + Double.SIZE);
System.out.println("float size = " + Float.SIZE);

System.out.println("\n");
}
}
/
****************************************
********************************/
Here's what i get when i issue the following command:
# jamvm helloworld
Hello


both of these should be 0.1:
double var = 0.00000103455646584
float var = 0.0004:3256

double size = 64
float size = 32


After some researches i found a patch about the arm float parsing
http://www.mail-archive.com/classpa...g/msg08956.html

It seems to correct the problem, but is there someone who can explain
exactly the problem ?
On the other hand, i'd like to understand how the floats are managed
into the java code.
Since my hardware does not embed a FP unit and the linux kernel is
disabled how the float are processed ?
regards
greg



Roedy Green

2008-03-05, 4:35 am

On Tue, 4 Mar 2008 07:10:16 -0800 (PST), grp62 <grp62@yahoo.fr> wrote,
quoted or indirectly quoted someone who said :

>float var = 0.0004:3256


In standard Java you may not embed colons in the middle of numbers.

floats also must end with f.

float var = 0.0003256f;

"var" is a bad choice of variable name. It tells you nothing about
about the purpose. It also masquerades as a keyword. It is a keyword
in Pascal.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Roedy Green

2008-03-05, 4:35 am

On Tue, 4 Mar 2008 07:10:16 -0800 (PST), grp62 <grp62@yahoo.fr> wrote,
quoted or indirectly quoted someone who said :

>System.out.println("float var = " + fvar);


Looks like a bug. Try explicitly converting float to String.
See http://mindprod.com/applet/converter.html
for how.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew

2008-03-05, 8:22 am

Roedy Green wrote:
> "var" is a bad choice of variable name. It tells you nothing about
> about the purpose. It also masquerades as a keyword. It is a keyword
> in Pascal.


Pascal? Really? You're objecting on the basis of a conflict with Pascal?

--
Lew
Roedy Green

2008-03-06, 8:22 am

On Wed, 05 Mar 2008 07:57:13 -0500, Lew <lew@lewscanon.com> wrote,
quoted or indirectly quoted someone who said :

>Pascal? Really? You're objecting on the basis of a conflict with Pascal?


On general principles I object to variable names that remotely look
like keywords.

var IS a keyword is some languages.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com