Home java What is the java.math.sin algorithm?

What is the java.math.sin algorithm?

Author

Date

Category

and whether it will not be faster to replace it with a static table (array Float [90000] ) values ​​of this function on the interval [0; 90 degrees], if there are many trigonometric applications Operations in which the accuracy is not needed more than two signs after the comma. At the same time, override the rest of the trigonometry through the new implementation of SIN . Such a table will take 4 (dimension Float ) * 90 * 1000 (three decimal sign) ~ 300kbB in memory. Is it worth it? What else can underwater stones be with this approach?


Answer 1, Authority 100%

  • Personally, it seems to me that it is possible to persist in the performance of the sinus only if there is the huge number of calculations, that is, with any engineering calculations. In this case, the accuracy is usually very significant, which means an approach with caching of sinus values ​​is impractical.

  • In this case, a variety of calculations in Native is much more preferable, where, for example, will be used SIMD.

You can also potentially draw out these kinds of GPU, What should be an order of magnitude better than the proposed trick with caching.

  • It is difficult to be sure that Jit will generate a good code for the proposed optimization. In such things it makes sense to think about the questions of the following type:
  • How does a table with predestines put in the processor cache?
  • Which assembler code will be generated for each function call?
  • Think about such things, having a thick layer from Jit and Baitcode is extremely difficult, because Java in itself is not intended for microoptimizations.

  • Here, by the way, still interesting discussions on the topic:


  • (Update) Once it is about GameDev'e , then God himself ordered to make heavy calculations in the shader.

Answer 2, Authority 114%

As a person involved in the wrecks, I will say this:

  1. Matfunctions in Java are not implemented on a pure Java, but a call to native (blue) functions. Java’s sources are enough, everything is clearly seen: Prouflink
  2. in the native part, the implementation of SIN / COS depends on the platform. The X86 family processors are implemented on an assembler by calling the FSIN / FCOS function built into the floating point processor.
  3. For other Sun processors, it uses (or rather now Oracle) is widely known in the narrow circles of the computers library fdlibm
  4. Actually Sinus source shows that there are some kind of power polynomials of the 13th degree.

Yes, and actually the answer to the question of the author: Replace sinus will not be faster 🙂


Answer 3, Authority 29%

I will not Baba Wange, if I say that it is implemented there through a decomposition in a series of Taylor. And if the guys from SUN really tried, they were replaced by the detonation of a series of Taylor to minimax in Chebyshev.

If you need to count the angles with a low accuracy (2 characters as you wrote), then it is better to do it through this algorithm: Cordic .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions