Math.sqrt?

Hi there, I recognised, that there is no sqrt() function in kvm...a^(1/2) works neither....any suggestion on how implementing the squareroot?thxcharly
[199 byte] By [JebeDiAH] at [2007-9-26 15:45:48]
# 1

Since MIDP does not support floating point numbers, they most likely left out most real calculations. If you still want to do it, here are a couple of sites which discuss various algorithms, but be prepared for soem work.

http://jwilson.coe.uga.edu/EMT668/EMAT4680.folders/Nowlen/squareroot.html

http://www.math.toronto.edu/mathnet/questionCorner/sqrootcalc.html

http://www-vis.imag.fr/AcornDemos/Techies/SquaRoot.html

d1camero at 2007-7-2 18:45:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
You should use a fixed point library like FPLib or MathFP. http://home.rochester.rr.com/ohommes/MathFP/ http://bearlib.sourceforge.net/
mopfattn at 2007-7-2 18:45:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
And just for the recorda^(1/2)would give 'a' ;Pa XOR (1/2) = a XOR 0 = alogically anyway ;Prob,
Abuse at 2007-7-2 18:45:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

Try the next piece of code; it calculates the integer closest to the square root of the argument (or zero if the argument is less than 0):

public static int sqrt(int i) {

if (i < 0) return 0;

if (i < 3) return 1;

i--;

int j = i;

int k = 0;

while (j != k) {

k = j;

j = (k + i / k + 1) / 2;

}

return j;

}

Good luck,

-Ernst

ernst3i at 2007-7-2 18:45:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
You can re-introduce float and double support, andmath package, you must have a compiler for youroperating system that provide native math lib, andan hardware (FPU).See : http://forum.java.sun.com/thread.jsp?forum=50&thread=138662
logbord at 2007-7-2 18:45:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6
Where do I download the MathFP 1.2.2 file to from the link http://home.rochester.rr.com/ohommes/MathFP/
fyp813 at 2007-7-2 18:45:47 > top of Java-index,Java Mobility Forums,Java ME Technologies...