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/classpath-patches@gnu.org/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 - 05 Mar 2008 08:20 GMT
>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
Lew - 05 Mar 2008 12:57 GMT
> "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?

Signature
Lew
Roedy Green - 06 Mar 2008 12:50 GMT
>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
Roedy Green - 05 Mar 2008 08:29 GMT
>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