开发者

Asin, Acos, Atan in J2ME

开发者 https://www.devze.com 2023-01-20 15:35 出处:网络
How could I use Math.asin() (.. etc.) in a J2ME application? 开发者_C百科(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

How could I use Math.asin() (.. etc.) in a J2ME application?

开发者_C百科(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?)


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.


It depends on version of target CLDC API.

  1. CLDC 1.0 doesn't supports any floating point operations (not saying asin/acos/atan). But there are some 3rd party developed packages/API's which supports FP operations e.g. MicroFloat
  2. CLDC 1.1 support FP operations, but still it's lacking asin/acos/atan. You can implement it yourself - it's relatively easy. Try to google and find alternate java sources for acos/atan/asin
0

精彩评论

暂无评论...
验证码 换一张
取 消