double() function in c++ or not? -


i hava following c++ code

#include <cstdlib> #include <iostream> #include <fstream> #include <time.h> #include <math.h>  using namespace std;  #define pi 3.1415926  int n; double* a,*b; double function(double);  double a(int j) {     double s=0;     int ii;     (int i=-n;i<n+1;i++)     {         s=s+function(2*pi*double(i)/(2*n+1))*cos(2*pi*double(j)*double(i)/(2*n+1));     }     if (j==0)         return 1/double(2*n+1)*s;     return 2/double(2*n+1)*s; } 

and there isn't declared function double(), , looked function in math.h library , haven't found such. can explain it, lambda expression or delegate ?

double(...) thought of way of saying (double)(...). recall when have class constructor takes parameters can write

myclass(params) 

and produce instance of myclass. c++ standard expanded same syntax primitive types well. syntax shorter cast, because not require parentheses around double .

note: in program above explicit double(i) unnecessary, because pi double, , multiplying int double produces double.

may not work primitive types names take multiple parts. example, unsigned int(12.4) will not compile under gcc.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -