Why are C++ trigonometric functions fast, but not that fast ? [message #1840940] |
Thu, 29 April 2021 10:03 |
BronxCruz BronxCruz Messages: 1 Registered: April 2021 |
Junior Member |
|
|
When people try to optimize numerical algorithms, there is a point when the profiler says a significant part of time is spent computing sin, cos, tan, sqrt, etc.
Re-implementing custom versions is often beneficial in term of CPU time (with tremendous gain sometimes !)essay writer
In videogames too, people like to implement faster (but less accurate version alas) of these functions.
So why is std::sin not the fastest possible version ? Is it a matter of branch vs branchless like for std::floor (managing temporary value overflowing has a cost) ? Something else ?
[Updated on: Wed, 05 May 2021 10:40] Report message to a moderator
|
|
|
Re: Why are C++ trigonometric functions fast, but not that fast ? [message #1840958 is a reply to message #1840940] |
Thu, 29 April 2021 13:07 |
Tauno Voipio Messages: 742 Registered: August 2014 |
Senior Member |
|
|
The functions you mentioned are basic transcendental functions, which have a trade-off between accuracy and speed. The library functions aim to as accurate answer as possible within the limits of the floating-point representation.
The games can usually do without more than 3 digits of accuracy, and there are many ways to create fast but not-so-accurate versions instead.
--
Tauno Voipio
|
|
|
Powered by
FUDForum. Page generated in 0.02633 seconds