void mx2cmat(int m, int n, cmulti **A, int LDA, const mxArray *src) { mwSize size[2]={1,1}; mxArray *value=NULL; int i,j,k; for(j=0; j<n; j++){ for(i=0; i<m; i++){ // real part // prec value=mxGetField(src,j*m+i,"r_prec"); if(value!=NULL && mxIsInt64(value)){ rround(C_R(MAT(A,i,j,LDA)),(*(int64_t*)mxGetData(value))); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'prec'."); } // sign value=mxGetField(src,j*m+i,"r_sign"); if(value!=NULL && mxIsInt32(value)){ C_R(MAT(A,i,j,LDA))->_mpfr_sign=(*(int32_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'sign'."); } // exp value=mxGetField(src,j*m+i,"r_exp"); if(value!=NULL && mxIsInt64(value)){ C_R(MAT(A,i,j,LDA))->_mpfr_exp=(*(int64_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'exp'."); } // digits value=mxGetField(src,j*m+i,"r_digits"); if(value!=NULL && mxIsUint64(value)){ for(k=0; k<rget_size(C_R(MAT(A,i,j,LDA))); k++){ C_R(MAT(A,i,j,LDA))->_mpfr_d[k]=((uint64_t*)mxGetData(value))[k]; } } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'digits'."); } // imaginary part // prec value=mxGetField(src,j*m+i,"i_prec"); if(value!=NULL && mxIsInt64(value)){ rround(C_I(MAT(A,i,j,LDA)),(*(int64_t*)mxGetData(value))); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'prec'."); } // sign value=mxGetField(src,j*m+i,"i_sign"); if(value!=NULL && mxIsInt32(value)){ C_I(MAT(A,i,j,LDA))->_mpfr_sign=(*(int32_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'sign'."); } // exp value=mxGetField(src,j*m+i,"i_exp"); if(value!=NULL && mxIsInt64(value)){ C_I(MAT(A,i,j,LDA))->_mpfr_exp=(*(int64_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'exp'."); } // digits value=mxGetField(src,j*m+i,"i_digits"); if(value!=NULL && mxIsUint64(value)){ for(k=0; k<rget_size(C_I(MAT(A,i,j,LDA))); k++){ C_I(MAT(A,i,j,LDA))->_mpfr_d[k]=((uint64_t*)mxGetData(value))[k]; } } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'digits'."); } } } return; }
int nextpoweroftwo(int x) { // clog << "Calcuing " << x << endl; double logbase2 = log(x) / log(2); // clog << "logbase2: " << logbase2 << endl; // clog << "rround: " << rround(pow(2,ceil(logbase2))) << endl; return rround(pow(2,ceil(logbase2))); }
int distance_between_cities(City origin, City destination) { double result, l1, l2, delta; l1 = deg2rad(origin.lat); l2 = deg2rad(destination.lat); delta = deg2rad(destination.lng - origin.lng); result = acos(sin(l2) * sin(l1) + cos(l2) * cos(l1) * cos(delta)) * EARTH_RADIUS; return rround(result); }