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

后端 未结 4 600
耶瑟儿~
耶瑟儿~ 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:32

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

    The JIT compiler should be able to inline the StrictMath.sin(a) call. So there's little point creating an extra native method for the Math.sin() case ... and adding extra JIT compiler smarts to optimize the calling sequence, etcetera.

    In the light of that, your objection really boils down to an "elegance" issue. But the "pragmatic" viewpoint is more persuasive:

    • Fewer native calls makes the JVM core and JIT easier to maintain, less fragile, etcetera.

    • If it ain't broken, don't fix it.

    At least, that's how I imagine how the Java team would view this.

提交回复
热议问题