

PREV PACKAGE NEXT PACKAGE  FRAMES NO FRAMES 
float
and double
datatypes.
See:
Description
Class Summary  

MicroDouble  A software implementation of IEEE754 double precision math which does not
rely on the double data type. 
MicroFloat  A software implementation of IEEE754 single precision math which does not
rely on the float data type. 
Provides classes for performing IEEE754 floatingpoint arithmetic on
JVM implementations which lack native float
and double
datatypes. This is intended for use on
"micro" devices such as mobile phones, which implement the
CLDC 1.0 specification.
Note that CLDC
1.1 includes native floatingpoint support, so you don't need this library
when running on a CLDC 1.1 JVM.
The classes in this package overload the int
and long
data types by storing float
and double
data in them,
respectively. The format is the same one used by
Float.floatToIntBits(float)
Double.doubleToLongBits(double)
When working with these
values, you should be careful to avoid integer arithmetic, comparison, and
typecasts, all of which can lead to meaningless results.
For the sake of simplicity,
parameter types and return values are frequently
referred to in this documentation as double
or float
types when their actual type is long
or int
.
Although literally incorrect, this means that the values are treated as
a double
or float
.
Generally speaking, the methods in this package duplicate J2SE native floating point functions exactly. However there are some exceptions:
strictfp
block,
and for elementary function like sin and log, for which there is no way to
disable use of extended precision.String
conversion methods use a different technique
from the implementations in Float
and
Double
, and are sometimes less accurate. I believe the
error is no more than one ulp in all cases. Although not identical to their
J2SE counterparts,
toString
and parseFloat
/ parseDouble
should at least be consistent with one another. In other words
MicroDouble.parseDouble(MicroDouble.toString(d)) == d
.Math.rint
and Math.round
,
and others have reported problems with Math.pow
and
Math.tan
.
// old function using native floating point arithmetic public double averageThreeNumbers(double a, double b, double c) { return (a + b + c) / 3; } // new function using microfloat arithmetic import net.dclausen.microfloat.*; private static final long THREE = 0x4008000000000000L; public long averageThreeNumbers(long a, long b, long c) { return MicroDouble.div(MicroDouble.add(MicroDouble.add(a, b), c), THREE); }You can obtain constants like
THREE
above by having a simple
J2SE helper class with a main method like this:
public static void main(String[] args) { System.out.println(Long.toHexString(Double.doubleToLongBits(3))); }When building this package for a J2ME midlet or other memorysensitive target, you should use an obfuscator such as RetroGuard or ProGuard. This will strip out code for methods which you aren't using, in addition to doing other size optimizations. Typically this results in a much smaller JAR file.
Visit the project homepage at http://www.dclausen.net/projects/microfloat for more information and updates.
java.lang.Math
. Many of the corresponding functions
in MicroDouble
are ports from FDLIBM.Copyright (C) 2003, 2004 David Clausen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place  Suite 330, Boston, MA 021111307, USA. Portions of this software are derived from FDLIBM, which contained the following notice: ==================================================== Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. Developed at SunSoft, a Sun Microsystems, Inc. business. Permission to use, copy, modify, and distribute this software is freely granted, provided that this notice is preserved. ====================================================


PREV PACKAGE NEXT PACKAGE  FRAMES NO FRAMES 