Asin, Acos, Atan in J2ME

╄→尐↘猪︶ㄣ 提交于 2019-12-01 14:18:04

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!