Cmath header confusion

What is a namespace for mathematical functions? Global or std?

Consider cos . It has 3 overloads. But there is also a legacy cosfrom math.h. C knows nothing about function overloading. Therefore, cos(x)it cannot be allowed until cos(float). The solution is to explicitly invoke the version with one precision cosf(x). Did I miss something?

Thank.

+3
source share
4 answers

You get the same features, including <math.c>and <cmath>in C ++, the only differences are the name space. I.E. including <math.h>also gives you an overload.

, ++ 03 <math.h> , , std <cmath> , std, .

, ++ 0X . <math.h> , , , std, <cmath> , std , , .

+3

std. cmath using std::cos;.

+3

cXXX std. , .

++ 0x, , D.7:

2/ C, name.h, , , cname, . , (3.3.6) std - (7.3.3).

3/[: <cstdlib>, , std. . <stdlib.h>, , , C. std. -end ]

D.5 ++ 03 ( , ):

2/ C, name.h, , , cname, std -.

3/[: <cstdlib> std. <stdlib.h> , C. -end ]

" " XXX.h, ( ).

+1

++, .

There are three cos options:

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

But if you use only C or you want to use only a double version of this function with this name. The float function is cosf.

0
source

All Articles