J2ME Polish
J2ME Polish 2.4 Documentation
Enough Software

Floater


Floater allows you to use floating point calculations as well as Math.sin() etc calls on CLDC 1.0 devices as well.
Floater Logo

Introduction

J2ME environments often suffer from certain features in the JVM because of the constraints of the hardware. This means that code needs to be specially written for or ported to a special target environment. Support for double/float primitive data types is not mandatory in the J2ME specification. On CLDC 1.0 devices all methods and classes that use floating points are missing in the API. For many applications this is a huge disadvantage as a lot of arithmetic should be carried out on floating point numbers. To follow the Java paradigm "write once, run everywhere" Floater allows the programmer to write code using these primitive datatypes and transform the generated classes later to not use them anymore by replacing them with operations using long or int. This transformation is done only for target devices that do not support the CLDC 1.1 configuration, of course. This is done by utilizing the MathFP library that provides floating point operations based on integer primitive types.

MathFP is a small and fast library using a fixed-point format to represent doubles and floats.

Usage

Floater is very easy to activate: just add a <postcompiler name="floater" /> tag to your build.xml script:

<target name="j2mepolish">
  ...
  <j2mepolish>
    ...
    <build>
      ...
      
      <postcompiler name="floater">
		<parameter name="verbose" value="false" />
      </postcompiler>

      ...
    </build>
    ...
  </j2mepolish>
  ...
</target>

You can use the optional "verbose" parameter to print out more information about the actions of Floater.

Limitations

Floater has two limiations:

  • Math.ceil(), Math.floor() are not supported.
  • Having identical methods that only differ by one float/int or one double/long parameter cannot be resolved correctly, since Floater uses internally int-values to simulate floats and long-values to simulate doubles. Following example will fail and abort the build process:
    public void doSomething( float f ) {...}
    public void doSomething( int i ) {...}
    

 

back to top