Why is std::sin() and std::cos() slower than sin() and cos()?

前端 未结 4 1827
小蘑菇
小蘑菇 2021-01-01 13:14

Test code:

#include 
#include 

const int N = 4096;
const float PI = 3.1415926535897932384626;

float cosine[N][N];
float sine[N][         


        
4条回答
  •  难免孤独
    2021-01-01 13:32

    I guess the difference is that there are overloads for std::sin() for float and for double, while sin() only takes double. Inside std::sin() for floats, there may be a conversion to double, then a call to std::sin() for doubles, and then a conversion of the result back to float, making it slower.

提交回复
热议问题