Floating Point Support in Java ME

Anyone who has been writing Java ME (J2ME) applications for a while has probably run into one of the more frustrating limitations of the platform, lack of support for the floating point primitive types: float and double. More accurately, there is no floating point support in CLDC 1.0. If you can, use CLDC 1.1, which does have floating point support. If that’s not a viable option, another possibility is to use one of the fixed point math libraries that are freely available, or to roll your own solution.

One popular third-party library is MathFP, which according to the author is free for non-commercial use. Note, however, that every operation is a method call; that can turn into a lot of overhead. If you are writing an application where performance is a major concern (i.e. video games), your best bet is to roll your own fixed point math code, and implement it inline rather than through method calls.

The following article provides some good examples of using inline fixed point arithmetic in a Java application: Optimizing Fixed Point (FP) Math with J2ME

Bookmark this article: del.icio.us Digg Furl Reddit blogmarks Google Spurl StumbleUpon Technorati Yahoo!

Tags: , , , , , , ,

One Response to “Floating Point Support in Java ME”

  1. Sebas86 Says:

    Thanks for that information. I need floating point support to make a small project. :)

Leave a Reply

You must be logged in to post a comment.