Why does Math.sin() delegate to StrictMath.sin()?

后端 未结 4 698
耶瑟儿~
耶瑟儿~ 2020-12-20 10:56

I was wondering, why does Math.sin(double) delegate to StrictMath.sin(double) when I\'ve found the problem in a Reddit thread. The mentioned code f

4条回答
  •  悲&欢浪女
    2020-12-20 11:29

    The question assumes that the JVM actually runs the delegation code. On many JVMs, it won't. Calls to Math.sin(), etc.. will potentially be replaced by the JIT with some intrinsic function code (if suitable) transparently. This will typically be done in an unobservable way to the end user. This is a common trick for JVM implementers where interesting specializations can happen (even if the method is not tagged as native).

    Note however that most platforms can't simply drop in the single processor instruction for sin due to suitable input ranges (eg see: Intel discussion).

提交回复
热议问题