Math和StrictMath

Math位于java.lang包下,当我们试图调用Math.sin方法时候,在Math类中显示的是StrictMath中的 sin方法

public static double sin(double a) {
	return StrictMath.sin(a); // default impl. delegates to StrictMath
    }

StrictMath中仅仅定义了方法,并且申明为static native

/** 
    * Returns the trigonometric sine of an angle. Special cases: 
    * <ul><li>If the argument is NaN or an infinity, then the  
    * result is NaN. 
    * <li>If the argument is zero, then the result is a zero with the 
    * same sign as the argument.</ul> 
    * 
    * @param   a   an angle, in radians. 
    * @return  the sine of the argument. 
    */  
   public static native double sin(double a);  

在Math类中,为了达到最快的性能,所有的方法都使用计算机浮点单元中的历程。如果得到一个完全可预测的结果比运行速度更重要的话,就应该使用StrictMath类。它使用“自由发布的Math库”实现算法,以去报在所有平台上得到相同的结果。有关这些算法的源代码请参阅 http://www.netlib.org/fdlibm/index.html

参考:

        Math类还提供指数函数以及它的反函数--自然对数  Math.exp    Math.log

        Math类还提供了两个用于表示π和e常量的近似值 Math.PI    Math.E

提示:从JDK5.0开始,不必在数学方法和常量名前添加前缀Math,而只用在源文件的顶部加上下列内容就可以     Import static java.lang.Math.*;

        System.out.println("The square root of \u03C0 is "+sqrt(PI));


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值