Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2me 8/9

 
Oiram mimi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I am makeing some simple calculations for an game. i am using j2me but i have got one real problem.
While i was reading the api i found out that j2me is not able to make divisions.
so when i try something like 9/8 then i get an 1.
and not 1.125.

thx for help
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Floating point is not supported in CLDC v1.0. You can try other third party math libraries such as the MathFP. MathFP only increases your application size by 4kB.
Or, you can run your applications on CLDC v1.1 (MIDP v2.0) devices.
[ December 08, 2003: Message edited by: Michael Yuan ]
 
serge masse
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
MIDP2 supports divisions but with the classic CLDC 1.0, i.e., without any additional specifications, it does not support floating points arithmetics, only integer arithmetics. What you need is floating point support. There are 2 ways to get this:
1) Use the free MathFP API from http://www.jscience.net/ or from http://home.rochester.rr.com/ohommes/MathFP/
2) Use the new CLDC 1.1, which includes the Sun API for floating point support. The new Wireless Toolkit 2.1 beta supports CLDC 1.1. See http://java.sun.com/products/j2mewtoolkit/index.html
btw, for applications to be released now or in the next few months, I recommend MathFP as very few JREs support CLDC 1.1.
Someone should list the JREs supporting MIDP2 and CLDC 1.1 ;-)
serge
[ December 09, 2003: Message edited by: serge masse ]
 
serge masse
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Michael,
when I started to write my post you had not posted yet. I don't think that my post is better than yours.
serge
 
David Price
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Yuan:
Or, you can run your applications on CLDC v1.1 (MIDP v2.0) devices.

Just a clarification here: MIDP 2.0 and CLDC 1.1 are independent, i.e. a phone could support any of:
CLDC 1.0 and MIDP 1.0 (most phones today, e.g. Nokia 7210)
CLDC 1.0 and MIDP 2.0 (e.g. Nokia 6600)
CLDC 1.1 and MIDP 1.0 (no examples I'm aware of)
CLDC 1.1 and MIDP 2.0 (e.g. Nokia 6230)
 
Nikolay Klimchuk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more solution is a free source the henson.midp.Float class
http://henson.newmail.ru/j2me/Float.htm
 
Sherry Nelson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using CLDC v1.1 but it looks like it does not fully support Float objects. I found that I cannot instantiate a Float with a string parameter, only with a float primitive.
 
Robert Virkus
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the CLDC/1.1 when it is available and the MathFP API when only the CLDC/1.0 configuration is available. This is done by preprocessing - this will only increase your application size it is really needed:



The above example assumes that you are using J2ME Polish (www.j2mepolish.org), which has an integrated device database and very powerful preprocessing capabilities.

Best regards,
Robert
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to increase your app size, you can do 9 << 6 / 8, and use the result wisely.

Nice and Easy!
[ August 02, 2004: Message edited by: Roseanne Zhang ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic