Using double on cldc 1.0

Hello.
I’m trying to manage double numbers on my cldc 1.0 devices. (Motorola V620 phone).

I know that to do that I need an external library like MathFP or MicroDouble.
MathFP haven’t all the method that I need.
MicroDouble is what I need but I’m not able to use it.

Is there someone that can help me using it?
A piece of code to implement this library and a simple explanation on how to do that.

It can be enough also a piece of code that add only to double numbers.
Example:

2.5+2.8=5.3
This code is enough.
Please help me

Bump!

No idea what CDLC is, but from a one second glance to the MicroDouble doc:

long res = MicroDouble.add( new MicroDouble("2.5").doubleValue(), new MicroDouble("2.8").doubleValue() );

2 second look:

long res = MicroDouble.add( MicroDouble.parseDouble("2.5"), MicroDouble.parseDouble("2.8"));

If used often, I’d personally write (the author did not make the class final ):

class D extends MicroDouble{}

long res = D.add( D.parseDouble("2.5"), D.parseDouble("2.8"));

:wink:

(This thread would be better served in the J2ME forum section)

Presumably if you were to use MathFP it could be written like this:-
long a = MathFP.toFP(“2.5”);
long b = MathFP.toFP(“2.8”);
long result = MathFP.add(a, b);
(editted: my previous attempt was wrong)

But Herks solution is much easier to read.

There are many good tutorials about fixed-point math available, and it is always worth studying, but now that CLDC-1.1 is slowly becoming common-place it can be skipped should you wish to avoid it.