How could I use Math.asin()
(.. etc.) in a J2ME application?
(I've looked at Real Java (and it looks like it could do this) but it says I should avoid converting from a string. How could I create a new Real
from a double
value?)
How could I use Math.asin()
(.. etc.) in a J2ME application?
(I've looked at Real Java (and it looks like it could do this) but it says I should avoid converting from a string. How could I create a new Real
from a double
value?)
It depends on version of target CLDC API.
Since MIDP 2.0 this should work:
public static double asin(double a)
{
// -1 < a < 1
// The function isn't very precise
final double epsilon=1.0E-7; // Use this to adjust precision
double x=a;
// Newton's iterative method
do x-=(Math.sin(x)-a)/Math.cos(x);
while (Math.abs(Math.sin(x)-a)>epsilon);
return x;
// returned angle is in radians
}
But hey, that Real - Java looks very nice. You definitely should use it.
If you assign the number using String only one or a few times, that won't affect your application's speed.