static void ReplaceTime(TDateTime & DateTime, const TDateTime & NewTime) { DateTime = Trunc(DateTime); if (DateTime >= 0) DateTime = DateTime + Abs(Frac(NewTime)); else DateTime = DateTime - Abs(Frac(NewTime)); }
void UniString::RStrip(void) { size_t i = Length(); while (i && uni_isspace(At(i - 1))) i--; Trunc(i); }
UniString::UniString(const UniString& other, size_t offset /* = 0 */, size_t length /* = OpDataFullLength */) : m_data(other.m_data) { OP_ASSERT(IsUniCharAligned(m_data.Length())); if (offset) Consume(offset); if (length < Length()) Trunc(length); OP_ASSERT(IsUniCharAligned(m_data.Length())); }
DbgSpline( Point ptPos1, Point ptDir1, Point ptPos2, Point ptDir2, int nColor, float fWidth, float fStep, int nDivs): m_nColor(nColor), m_fWidth(fWidth), m_nDivs(nDivs) { Point pt[] = {ptPos1, ptPos1 + ptDir1, ptPos2 - ptDir2, ptPos2}; if( fStep ) { float len = SplineLenEst(pt); m_nDivs = 1 + Trunc(len / fStep); } SplineCoefs(pt, m_coefs); }
OP_STATUS UniString::AppendVFormat(const uni_char *format, va_list args) { size_t buf_len = 0; uni_char *buf = GetAppendPtr_NoAlloc(buf_len); OP_ASSERT(buf_len <= Length()); // GetAppendPtr_NoAlloc() adds buf_len to Length() int result; // first, try to append without allocation #ifdef va_copy // must use va_copy() in order to preserve args for reuse below va_list args_copy; va_copy(args_copy, args); result = uni_vsnprintf(buf, buf_len, format, args_copy); va_end(args_copy); #else // va_copy result = uni_vsnprintf(buf, buf_len, format, args); #endif // va_copy if (result < 0) // uni_vsnprintf() returned error { Trunc(Length() - buf_len); return OpStatus::ERR; } else if (static_cast<size_t>(result) >= buf_len) { // buf was too short, allocate to make enough room Trunc(Length() - buf_len); buf_len = result + 1; buf = GetAppendPtr(buf_len); RETURN_OOM_IF_NULL(buf); result = uni_vsnprintf(buf, buf_len, format, args); } OP_ASSERT(static_cast<size_t>(result) < buf_len); Trunc(Length() - (buf_len - result)); return OpStatus::OK; }
char ASCIIShade(double x) { if(IsNaN(x)) return 'E'; if(IsInf(x)==1) return 'I'; else if(IsInf(x)==-1) return 'i'; int index = (int)Trunc(x*8) + 7; if(index < 0) index=0; if(index >= kNumAsciiShades) index=kNumAsciiShades-1; if(index == 7) { if(x > 0) return kAsciiShades[8]; else if(x < 0) return kAsciiShades[6]; else return kAsciiShades[7]; } return kAsciiShades[index]; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /*printf("Mex Function Entered Successfully\n");*/ static double *x, *y, *z, *m; static int *mask; static int i, size, rowLen, masksize; static int nParm = 0; static int init = 1; /* init = 1 means 'initialization loop' */ static int jacobian = 0; /* set this if you need the Jacobian matrix */ static Files files; static char *inputfile = NULL; static ScoreOutput out; out.score = 1e38; /*start with a very large number*/ out.penalty = 0; out.size_resid_arr = 0; out.jacobian = NULL; out.residuals = NULL; /* allocate memory for static file names */ files.inputfile = ( char * ) calloc( MAX_RECORD, sizeof( char ) ); files.statefile = ( char * ) calloc( MAX_RECORD, sizeof( char ) ); inputfile = mxArrayToString(prhs[2]); /*printf("%s\n", inputfile);*/ rowLen = mxGetN(prhs[0]); if (rowLen < nParm) { /*for some strange and/or paranormal reason rowLen is 1 whenever local search is called, despite that the input array length is still 56 */ rowLen = nParm; } else { nParm = rowLen; } masksize = mxGetN(prhs[1]); mask = (int *) calloc( masksize, sizeof(int) ); x = mxGetPr(prhs[0]); m = mxGetPr(prhs[1]); for (i=0; i<masksize; i++) { mask[i] = (int) m[i]; } for (i=0; i<nParm; i++) { x[i] = Trunc(x[i], 5); /*this is needed to avoid errors due to lack of precision*/ /*if (x[i] > 100) printf("Warning - %lf > 100 for i = %d!!!\n", x[i], i);*/ } plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); y = mxGetPr(plhs[0]); strcpy( files.inputfile, inputfile); sprintf( files.statefile, "%s.state", files.inputfile ); /* check if a state file exists (access() is in unistd.h) */ /*if( 0 == access( files.statefile, F_OK ) ) stateflag = 1; //use this for restore when implemented*/ MoveX(x, mask, &out, &files, init, jacobian, 1); /*0 Rkck, 1 Direct-Band */ /*printf("SCORE = %lf, PENALTY = %lf, RETURNED %lf\n", out.score, out.penalty, out.score + out.penalty);*/ /*printf("RETURNED %lf\n", out.score + out.penalty);*/ if (out.score < 0) { /* maybe eliminate later and deal only with 1e38 */ printf("OUT_OF_BOUND - setting score to 0 and penalty to 1e38\n"); out.score = 0; /*out.score = 1e38; /*testing (without penalties) purposes*/ /*out.penalty = 0; /*testing (without penalties) purposes*/ out.penalty = 1e38; } size = out.size_resid_arr; plhs[1] = mxCreateDoubleMatrix(1,size,mxREAL); z = mxGetPr(plhs[1]); for (i=0; i<size; i++) { z[i] = out.residuals[i]; } y[0] = out.score + out.penalty; /*comment this to test without penalties*/ plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); init = 0; mxFree(inputfile); free(files.inputfile); free(files.statefile); free(out.jacobian); free(out.residuals); free(mask); return; }
String PropertyUtils::getFormattedNumber( String numberStr, IsoString numberFormat ) { if ( numberStr.IsEmpty() ) return numberStr; size_t im = numberFormat.Find( 'm' ); if ( im == String::notFound ) return String().Format( numberFormat.c_str(), stringToFloatSafe( numberStr ) ); numberFormat.DeleteRight( im ); numberFormat.DeleteLeft( 1 ); StringList tokens; numberFormat.Break( tokens, '.', true/*trim*/ ); size_t fraction = stringToIntSafe( tokens[1] ); size_t width = stringToIntSafe( tokens[0] ) - fraction; assert( width > 0 ); int hours = Trunc( stringToFloatSafe( numberStr ) ); switch ( fraction ) { case 3: { int minutes = Trunc( (stringToFloatSafe( numberStr ) - hours)*60 ); IsoString formatStr = '%' + IsoString().Format( "%dd",width ) + ":%02d"; return String().Format( formatStr.c_str(), hours, Abs( minutes ) ); } case 5: { int minutes = Trunc( (stringToFloatSafe( numberStr ) - hours)*60 ); int minutesfrac = Trunc( ((stringToFloatSafe( numberStr ) - hours)*60 - minutes)*10); IsoString formatStr = '%' + IsoString().Format( "%dd", width ) + ":%02d.%d"; return String().Format( formatStr.c_str(), hours, Abs( minutes ), Abs( minutesfrac ) ); } case 6: { int minutes = Trunc( (stringToFloatSafe( numberStr ) - hours)*60 ); int seconds = Trunc( ((stringToFloatSafe( numberStr ) - hours)*60 - minutes)*60 ); IsoString formatStr = '%' + IsoString().Format( "%dd", width ) + ":%02d:%02d"; return String().Format( formatStr.c_str(), hours, Abs( minutes ), Abs( seconds ) ); } case 8: { int minutes = Trunc( (stringToFloatSafe( numberStr ) - hours)*60 ); int seconds = Trunc( ((stringToFloatSafe( numberStr ) - hours)*60 - minutes)*60 ); int secondsfrac = Trunc( (((stringToFloatSafe( numberStr ) - hours)*60 - minutes)*60 - seconds)*10 ); IsoString formatStr = '%' + IsoString().Format( "%dd", width ) + ":%02d:%02d.%d"; return String().Format( formatStr.c_str(), hours, Abs( minutes ), Abs( seconds ), Abs( secondsfrac ) ); } case 9: { int minutes = Trunc( (stringToFloatSafe( numberStr ) - hours)*60 ); int seconds = Trunc( ((stringToFloatSafe( numberStr ) - hours)*60 - minutes)*60 ); int secondsfrac = Trunc( (((stringToFloatSafe( numberStr ) - hours)*60 - minutes)*60 - seconds)*100 ); IsoString formatStr = '%' + IsoString().Format( "%dd", width ) + ":%02d:%02d.%02d"; return String().Format( formatStr.c_str(), hours, Abs( minutes ), Abs( seconds ), Abs( secondsfrac ) ); } default: return String(); } }