MathFP

- Fixed Point Integer Math -

Introduction

MathFP is implemented to provide developers the capability to do calculations involving fractions on java virtual machines with no support for floats or doubles. For example the KVM (K Virtual Machine) and the CLDC (Connceted Limited Device Configuration) do not support these primitive datatypes.

Instead of implementing a Float class based on the IEEE 754-1985 standard MathFP uses fixed-point integers. Fixed point integers are just like floats in most cases approximations of numbers. How ever in the domain that fixed-point integers can work they have two advantages over floating point numbers.

Within the domain of the fixed point integer all numbers have an equal distance to eachother whereas floats increase the distance between numbers when the exponent increases.

Fixed-point integers are faster then floating point operations if both are implemented on the same platfrom and language. This great speed advantage is the main reason why MMX and a lot of DSP processors use fixed-point math. Most of the operations are based on bit shifts which are the fastest machine instructions.

If the MathFP code would be part of the VM then both execution and size would be positively affected.

The current MathFP class is just over 4kb and provides most of the math functions provided by the (see the table below) Java 2 java.lang.Math class. Besides these mathematical functions one can change the precision (i.e. number of bits used for the fraction) dynamically during runtime.

Mathematical Operations

Operation Description Operation Description
abs(n)absolute number of nacos(n)arc cosine of n
add(n,m) or n + madd n and m asin(n)arc sine of n
sub(n,m) or n - m subtract m from nsin(n)sine of n
mul(n,m)multiply n with mcos(n)cosine of n
div(n,m)divide n by mtan(n)tangent of n
sqrt(n)extract root of ncot(n)cotangent of n
max(n,m)biggest number of n,mround(n,d)round n to d digits
min(n,m)smallest number of n.mlog(n)logarithm of n
exp(n)e raised to npow(b,e)b raised to e
atan(n)arctangent of natan2(y,x)Pricipal atan of y/x
Table 1. The MathFP Mathematical functions

Platform Versions

MathFP is available for both J2ME and Waba. The Waba version is only available in a 32 bit version as part of the net.jsciecne.math.waba package. For the J2ME platform there are different versions. The net.jscience.math package contains the 64 bit version based on the long datatype and is intended for the CLDC on top of the KVM. The class in net.jscience.math.kvm is intended to be used on J2ME platfroms lacking support for the long datatype.

And for compatibility reasons there is a class in the net.jscience.util package to allow existing applications based on the MathFP version 1.X architecture to use the new algorithms and possible fixes. However new application should be written using the classes provided in the packages part of net.jscience.math

References

Below you will find links to the MathFP documentation, download section and other related material.
If you encounter problems or have suggestions please mail them to
Onno Hommes.

The MathFP library software may be used for any non-commercial purpose whatsoever without acknowledgment. It is distributed in the hope that it will be useful but WITHOUT WARRANTY. MathFP will be distributed under a Liberal Source Software (LSS) license for commercial purposes.

Onno Hommes, Rochester NY
jScience Technologies
www.jscience.net