本文介绍了J2ME中的Asin,Acos,Atan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在J2ME应用程序中使用Math.asin()
(..等)?
How could I use Math.asin()
(.. etc.) in a J2ME application?
(我看过 Real Java (看起来它可以做到)说我应该避免从字符串转换.如何从double
值创建新的Real
?)
(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?)
推荐答案
从MIDP 2.0开始,此方法应该起作用:
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
}
但是,嘿, Real-Java 看起来非常不错.您绝对应该使用它.
如果仅使用一次或几次使用String分配数字,则不会影响应用程序的速度.
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.
这篇关于J2ME中的Asin,Acos,Atan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!