cmath header confusion

前端 未结 4 1819
深忆病人
深忆病人 2020-12-11 21:00

What is the namespace for math functions? Global or std?

Consider cos function. It has 3 overloads. But there is also legacy cos from math.

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 21:33

    If you are using C++ you can rely on the function overloading.

    There are three version of cos:

    double cos (      double x );
    float cos (       float x );
    long double cos ( long double x );
    

    But if you are using only C or you want portabilty only the double version of this function exists with this name. The float function is cosf.

提交回复
热议问题