void msgGetChapter( NetMessage *msg, int32_t idx ) { MSGINIT( msg, GetChapter, Command ); if( idx < 0 ){ strcpy( msg->data.URN, "<list all>" ); } else{ strcpy( msg->data.URN, "<in retrieval>" ); } msg->data.iVal1 = idx; set_NaN(msg->data.val1); set_NaN(msg->data.val2); msg->data.boolean = FALSE; }
/* Convert a (y, m, d) triple into a decimal number that represents the date. * Some care is required for overflow and the like. */ static decNumber *build_date(decNumber *res, int year, int month, int day) { int sign = 1, shift = -6, r = 0; if (check_date(year, month, day)) { set_NaN(res); return res; } if (year < 0) { year = -year; sign = -1; } switch (UState.date_mode) { case DATE_YMD: r = ((year * 100) + month) * 100 + day; shift = -4; break; case DATE_DMY: r = ((day * 100) + month)* 10000 + year; break; case DATE_MDY: r = ((month * 100) + day)* 10000 + year; break; } int_to_dn(res, r * sign); dn_mulpow10(res, res, shift); day_of_week(sign * year, month, day, &DispMsg); return res; }
/* Return the day of the week */ static int dateExtract(decNumber *res, const decNumber *x, int *y, int *m, int *d) { if (decNumberIsSpecial(x) || extract_date(x, y, m, d)) { set_NaN(res); return 0; } return 1; }
decNumber *decNumberAGM(decNumber *res, const decNumber *x, const decNumber *y) { int n; decNumber a, g, t, u; if (decNumberIsNegative(x) || decNumberIsNegative(y)) goto nan; if (decNumberIsSpecial(x) || decNumberIsSpecial(y)) { if (decNumberIsNaN(x) || decNumberIsNaN(y)) goto nan; if (dn_eq0(x) || dn_eq0(y)) goto nan; return set_inf(res); } decNumberCopy(&a, x); decNumberCopy(&g, y); for (n=0; n<1000; n++) { if (relative_error(&a, &g, &const_1e_32)) return decNumberCopy(res, &a); dn_add(&t, &a, &g); dn_div2(&u, &t); dn_multiply(&t, &a, &g); if (dn_eq0(&t)) return decNumberZero(res); dn_sqrt(&g, &t); decNumberCopy(&a, &u); } nan: return set_NaN(res); }
int ascanf_strdup ( ASCB_ARGLIST ) { ASCB_FRAME ascanf_Function *s1; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_strdup", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || (!s1->usage && ascanf_verbose) ) ){ fprintf( StdErr, " (warning: argument is not a valid string)== " ); } if( s1 && s1->usage ){ ascanf_Function *allocated; if( (allocated= Create_Internal_ascanfString( s1->usage, level )) ){ /* We must now make sure that the just created internal variable behaves as a user variable: */ allocated->user_internal= True; allocated->internal= True; *result= take_ascanf_address( allocated ); } else{ fprintf( StdErr, " (error: could not duplicate %s=\"%s\": %s)== ", s1->name, s1->usage, serror() ); ascanf_arg_error= True; *result= 0; } } } return(!ascanf_arg_error); }
/* * Convert Z = year, y = month, x = day to a valid date in X */ decNumber *dateFromYMD(decNumber *res, const decNumber *z, const decNumber *y, const decNumber *x) { if (decNumberIsSpecial(x) || decNumberIsSpecial(y) || decNumberIsSpecial(z)) return set_NaN(res); else { return build_date(res, dn_to_int(z), dn_to_int(y), dn_to_int(x)); } }
/* Conversion routines from Julian days to and from dates */ decNumber *dateToJ(decNumber *res, const decNumber *x) { if (decNumberIsSpecial(x)) err: set_NaN(res); else { int y, m, d; if (extract_date(x, &y, &m, &d)) goto err; int_to_dn(res, JDN(y, m, d)); } return res; }
decNumber *dateFromJ(decNumber *res, const decNumber *x) { if (decNumberIsSpecial(x) || dn_lt0(x)) set_NaN(res); else { const int j = dn_to_int(x); int y, m, d; JDN2(j, &y, &m, &d); return build_date(res, y, m, d); } return res; }
int ascanf_concat ( ASCB_ARGLIST ) { ASCB_FRAME ascanf_Function *s1; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ int idx= 0; char *rstring= NULL; for( idx= 0; idx< ascanf_arguments; idx++ ){ if( (s1= parse_ascanf_address(args[idx], 0, "ascanf_concat", (int) ascanf_verbose, NULL )) && s1->usage && !(s1->type== _ascanf_procedure || s1->type== _ascanf_function) ){ rstring= concat2( rstring, s1->usage, NULL ); } else if( s1 ){ if( s1->type== _ascanf_array && s1->N ){ int i; rstring= concat2( rstring, "{", ad2str( ASCANF_ARRAY_ELEM(s1,0), d3str_format, NULL ), NULL ); for( i= 1; i< s1->N-1; i++ ){ rstring= concat2( rstring, ",", ad2str( ASCANF_ARRAY_ELEM(s1,i), d3str_format, NULL ), NULL ); } rstring= concat2( rstring, ",", ad2str( ASCANF_ARRAY_ELEM(s1,i), d3str_format, NULL ), "}", NULL ); } else{ rstring= concat2( rstring, ad2str(s1->value, d3str_format, NULL), NULL ); } } else{ rstring= concat2( rstring, ad2str(args[idx], d3str_format, NULL), NULL ); } } if( rstring ){ ascanf_Function *allocated; if( (allocated= Create_Internal_ascanfString( rstring, level )) ){ /* We must now make sure that the just created internal variable behaves as a user variable: */ allocated->user_internal= True; allocated->internal= True; *result= take_ascanf_address( allocated ); } else{ fprintf( StdErr, " (error: could not duplicate %s=\"%s\": %s)== ", s1->name, rstring, serror() ); ascanf_arg_error= True; *result= 0; } xfree(rstring); } } return(!ascanf_arg_error); }
int ascanf_strcasecmp ( ASCB_ARGLIST ) { ASCB_FRAME_SHORT ascanf_Function *s1, *s2; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 2 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_strcasecmp", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || !s1->usage) ){ if( s1 ){ fprintf( StdErr, " (warning: 1st argument [%s=%s,\"%s\"] is not a valid string)== ", s1->name, ad2str( s1->value, d3str_format, 0), (s1->usage)? s1->usage : "<NULL>" ); } else{ fprintf( StdErr, " (warning: 1st argument is NULL)== " ); } } if( !(s2= parse_ascanf_address(args[1], 0, "ascanf_strcasecmp", (int) ascanf_verbose, NULL )) || (s2->type== _ascanf_procedure || s2->type== _ascanf_function || !s2->usage) ){ if( s2 ){ fprintf( StdErr, " (warning: 2nd argument [%s=%s,\"%s\"] is not a valid string)== ", s2->name, ad2str( s2->value, d3str_format, 0), (s2->usage)? s2->usage : "<NULL>" ); } else{ fprintf( StdErr, " (warning: 2nd argument is NULL)== " ); } } if( s1 && s2 && s1->usage && s2->usage ){ if( ascanf_arguments> 2 ){ if( args[2]< 0 ){ *result= strncasecmp( s1->usage, s2->usage, strlen(s2->usage) ); } else{ *result= strncasecmp( s1->usage, s2->usage, (int) args[2] ); } } else{ *result= strcasecmp( s1->usage, s2->usage ); } } else{ set_Inf(*result, 1); } } return(!ascanf_arg_error); }
/* Date of Easter. Input is the year and output is a date. * The input can either be specified as an integer year or as a * valid date in the current format. */ decNumber *dateEaster(decNumber *res, const decNumber *x) { int y; if (find_year(x, &y)) { set_NaN(res); return res; } else { int m, d; easter(y, &m, &d); build_date(res, y, m, d); } return res; }
int ascanf_basename ( ASCB_ARGLIST ) { ASCB_FRAME ascanf_Function *s1, *s2= NULL; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_basename", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || (!s1->usage && ascanf_verbose) ) ){ fprintf( StdErr, " (warning: argument is not a valid string)== " ); } if( s1 && s1->usage ){ char *bn= basename(s1->usage), *ext= NULL; ascanf_Function *allocated; if( ascanf_arguments> 1 && args[1] && (!(s2= parse_ascanf_address(args[1], 0, "ascanf_basename", (int) ascanf_verbose, NULL )) || (s2->type== _ascanf_procedure || s2->type== _ascanf_function || (!s2->usage && ascanf_verbose) )) ){ fprintf( StdErr, " (warning: second argument is not a valid string -- ignored)== " ); s2= NULL; } if( s2 ){ if( (ext= strrstr( bn, s2->usage )) ){ *ext= '\0'; } } if( (allocated= Create_Internal_ascanfString( bn, level )) ){ *result= take_ascanf_address( allocated ); } else{ fprintf( StdErr, " (error: could not duplicate basename(%s)=\"%s\": %s)== ", s1->name, bn, serror() ); ascanf_arg_error= True; *result= 0; } if( ext ){ /* if ext!=NULL, then also s2!=NULL */ *ext= s2->usage[0]; } } } return(!ascanf_arg_error); }
int ascanf_encode ( ASCB_ARGLIST ) { ASCB_FRAME ascanf_Function *s1; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_strdup", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || (!s1->usage && ascanf_verbose) ) ){ fprintf( StdErr, " (warning: argument is not a valid string)== " ); } if( s1 && s1->usage ){ char *encoded= NULL; int instring= True; sprint_string_string( &encoded, NULL, NULL, s1->usage, &instring ); *result= args[0]; if( encoded ){ ascanf_Function *allocated; if( ascanf_arguments> 1 && !ASCANF_TRUE(args[1]) ){ if( (allocated= Create_Internal_ascanfString( encoded, level )) ){ *result= take_ascanf_address( allocated ); xfree(encoded); } else{ fprintf( StdErr, " (error: could not duplicate encode(%s)=\"%s\": %s)== ", s1->name, encoded, serror() ); ascanf_arg_error= True; *result= 0; } } else{ xfree(s1->usage); s1->usage= encoded; } } else{ ascanf_arg_error= True; } } } return(!ascanf_arg_error); }
int ascanf_strlen ( ASCB_ARGLIST ) { ASCB_FRAME_SHORT ascanf_Function *s1; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_strlen", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || (!s1->usage && ascanf_verbose) ) ){ fprintf( StdErr, " (warning: argument is not a valid string)== " ); } if( s1 && s1->usage ){ *result= strlen( s1->usage ); } } return(!ascanf_arg_error); }
static void init_DWI() { if( !DWI_initialised ){ double nan; #ifdef DEBUG extern int PrintNaNCode; #endif set_NaN(nan); // these two keys should never occur: Double2IndexHTable.set_empty_key(nan); #ifdef DEBUG PrintNaNCode=1; fprintf( StdErr, "init_DWI(): set_empty_key(%s)\n", ad2str(nan, d3str_format, NULL) ); #endif // make a -NaN: I3Ed(nan)->s.s = 1; Double2IndexHTable.set_deleted_key(nan); #ifdef DEBUG fprintf( StdErr, "init_DWI(): set_deleted_key(%s)\n", ad2str(nan, d3str_format, NULL) ); #endif DWI_initialised = 1; } }
int runNEC ( ASCB_ARGLIST ) { ASCB_FRAME_SHORT double freq= 1, loopdelay= 0, delay= 0; int n, i, resetTemps= 1, dixms= 0; ascanf_Function *Time, *Pos, *sampleT, *Delta, *DDelta, *sumPos= NULL, *sumNeg= NULL, *sDTpos= NULL, *sDTneg= NULL, *Samples= NULL; ascanf_Function *sumPosHR= NULL, *sumNegHR= NULL, *sDTposHR= NULL, *sDTnegHR= NULL; NECtimer tmpTimer, tempsAbs, tpsEnMilliSec10ms= 0, dureeCycle1000; char *caller= "runNEC"; ascanf_arg_error= False; if( !(Time= parse_ascanf_address( args[0], _ascanf_array, caller, (int) ascanf_verbose, NULL )) ){ ascanf_emsg= " (array with time values is required) "; ascanf_arg_error= True; } if( !(Pos= parse_ascanf_address( args[1], _ascanf_array, caller, (int) ascanf_verbose, NULL )) ){ ascanf_emsg= " (array with Positions at each time is required) "; ascanf_arg_error= True; } if( (freq= args[2])<= 0 ){ fprintf( StdErr, "runNEC(): frequency should be positive, not %s: assuming 1Hz\n", ad2str(freq, d3str_format, 0 ) ); freq= 1; } if( (loopdelay= args[3])< 0 ){ fprintf( StdErr, "runNEC(): loopTime should be >=0 && <=1, not %s: assuming 0s\n", ad2str(loopdelay, d3str_format, 0 ) ); loopdelay= 0; } else if( loopdelay> 1 ){ fprintf( StdErr, "runNEC(): loopTime should be <=, not %s: assuming 1s\n", ad2str(loopdelay, d3str_format, 0 ) ); delay= 1; } if( (delay= args[4])< 0 ){ fprintf( StdErr, "runNEC(): sendDelay should be >=0 && <=1, not %s: assuming 0s\n", ad2str(delay, d3str_format, 0 ) ); delay= 0; } else if( delay> 1 ){ fprintf( StdErr, "runNEC(): sendDelay should be <=, not %s: assuming 1s\n", ad2str(delay, d3str_format, 0 ) ); delay= 1; } if( !(sampleT= parse_ascanf_address( args[5], _ascanf_array, caller, (int) ascanf_verbose, NULL )) ){ ascanf_emsg= " (array for returning sample times is required) "; ascanf_arg_error= True; } if( !(Delta= parse_ascanf_address( args[6], _ascanf_array, caller, (int) ascanf_verbose, NULL )) ){ ascanf_emsg= " (array for returning position at each sample time is required) "; ascanf_arg_error= True; } if( !(DDelta= parse_ascanf_address( args[7], _ascanf_array, caller, (int) ascanf_verbose, NULL )) ){ ascanf_emsg= " (array for returning speed at each sample time is required) "; ascanf_arg_error= True; } if( ASCANF_ARG_TRUE(8) ){ sumPos= parse_ascanf_address( args[8], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(9) ){ sumNeg= parse_ascanf_address( args[9], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(10) ){ sDTpos= parse_ascanf_address( args[10], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(11) ){ sDTneg= parse_ascanf_address( args[11], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(12) ){ Samples= parse_ascanf_address( args[12], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(13) ){ sumPosHR= parse_ascanf_address( args[13], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(14) ){ sumNegHR= parse_ascanf_address( args[14], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(15) ){ sDTposHR= parse_ascanf_address( args[15], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( ASCANF_ARG_TRUE(16) ){ sDTnegHR= parse_ascanf_address( args[16], _ascanf_array, caller, (int) ascanf_verbose, NULL ); } if( !ascanf_arg_error ){ Resize_ascanf_Array(sampleT, Time->N, NULL ); Resize_ascanf_Array(Delta, Time->N, NULL ); Resize_ascanf_Array(DDelta, Time->N, NULL ); Resize_ascanf_Array(sumPos, Time->N, NULL ); Resize_ascanf_Array(sumNeg, Time->N, NULL ); Resize_ascanf_Array(sDTpos, Time->N, NULL ); Resize_ascanf_Array(sDTneg, Time->N, NULL ); Resize_ascanf_Array(Samples, Time->N, NULL ); Resize_ascanf_Array(sumPosHR, Time->N, NULL ); Resize_ascanf_Array(sumNegHR, Time->N, NULL ); Resize_ascanf_Array(sDTposHR, Time->N, NULL ); Resize_ascanf_Array(sDTnegHR, Time->N, NULL ); } set_NaN(*result); if( !ascanf_arg_error ){ double t= 0, pt= 0; posVolantPred.i16= 0; dureeCycle1000= (unsigned int) (1000 / freq ); tmpTimer= 0; tempsAbs= 0; tpsEnMilliSec= 0; sVP=0, sVN=0, sTP=0, sTN=0, NN= 0; sommeVitesseNeg= sommeVitessePos = 0; sommeDTPos= 0; sommeDTNeg = 0; nbrEchantillonT = 0; nbrEchantillon0 = 0; tempsPredPos= 0; tempsPredNeg= 0; for( i= 0, n= 0; i< Time->N; i++ ){ double interval, skipTime= loopdelay; // emulate a delay due to sending data on the CANbus if( dixms ){ skipTime+= delay; } if( i && skipTime> 0 ){ double nan; set_NaN(nan); while( i< Time->N && ASCANF_ARRAY_ELEM(Time,i)< t+skipTime ){ if( sumPosHR ){ ASCANF_ARRAY_ELEM_SET( sumPosHR, i, nan ); } if( sumNegHR ){ ASCANF_ARRAY_ELEM_SET( sumNegHR, i, nan ); } if( sDTposHR ){ ASCANF_ARRAY_ELEM_SET( sDTposHR, i, nan ); } if( sDTnegHR ){ ASCANF_ARRAY_ELEM_SET( sDTnegHR, i, nan ); } i+= 1; } } pt= t; t= ASCANF_ARRAY_ELEM(Time,i); if( i ){ interval= 500 * 1000 * (t - pt); } else{ interval= 500 * 1000 * t; } dixms= 0; tmpTimer += (unsigned int) interval; tempsAbs += (unsigned int) interval; pVolant->i16= ASCANF_ARRAY_ELEM(Pos,i); // RJVB: la RAZ de tempsAbs se fait ici, pour pouvoir preserver la difference // tempsAbs-tempsPred (calculee en GestionCab) if( resetTemps ){ if( avec_tempsPred ){ extern NECtimer tempsPredPos, tempsPredNeg; NECtimer dtP, dtN; if( tempsPredPos < tempsAbs ){ // RJVB: s'assurer que la difference tempsAbs - tempsPred reste inchangee dtP= (unsigned) ((NECtimer)tempsAbs - tempsPredPos); } else{ dtP= 0; } if( tempsPredNeg < tempsAbs ){ // RJVB: s'assurer que la difference tempsAbs - tempsPred reste inchangee dtN= (unsigned) ((NECtimer)tempsAbs - tempsPredNeg); } else{ dtN= 0; } if( dtP> dtN ){ tempsAbs = dtP; tempsPredPos= 0; tempsPredNeg= tempsAbs - dtN; } else{ tempsAbs = dtN; tempsPredNeg= 0; tempsPredPos= tempsAbs - dtP; } } else{ tempsAbs= 0; } resetTemps = 0; } #define une_milliseconde 500 while (tmpTimer >= une_milliseconde) { tmpTimer -= une_milliseconde; tpsEnMilliSec += 1; } if ((tpsEnMilliSec - tpsEnMilliSec10ms) >= dureeCycle1000) { dixms = 1; tpsEnMilliSec10ms = tpsEnMilliSec10ms + dureeCycle1000; } if( GestionCabine( (NECtimer) tpsEnMilliSec, (NECtimer) tempsAbs) ){ dixms = 1; } if( sumPosHR ){ ASCANF_ARRAY_ELEM_SET( sumPosHR, i, sommeVitessePos ); } if( sumNegHR ){ ASCANF_ARRAY_ELEM_SET( sumNegHR, i, sommeVitesseNeg ); } if( sDTposHR ){ ASCANF_ARRAY_ELEM_SET( sDTposHR, i, sommeDTPos ); } if( sDTnegHR ){ ASCANF_ARRAY_ELEM_SET( sDTnegHR, i, sommeDTNeg ); } if( GestionCom( dixms, 0, tempsAbs ) ){ if( dixms ){ if( n< i ){ // output calculated values ("on the CANbus") ASCANF_ARRAY_ELEM_SET( sampleT, n, t ); ASCANF_ARRAY_ELEM_SET( Delta, n, pVolant->i16 ); { double Vp= (sTP)? (double)(sVP)/(double)(sTP) : 0, Vn= (sTN)? (double)(sVN)/(double)(sTN) : 0; ASCANF_ARRAY_ELEM_SET( DDelta, n, (Vp - Vn) * 500000.0 ); } if( sumPos ){ ASCANF_ARRAY_ELEM_SET( sumPos, n, sVP ); } if( sumNeg ){ ASCANF_ARRAY_ELEM_SET( sumNeg, n, sVN ); } if( sDTpos ){ ASCANF_ARRAY_ELEM_SET( sDTpos, n, sTP ); } if( sDTneg ){ ASCANF_ARRAY_ELEM_SET( sDTneg, n, sTN ); } if( Samples ){ ASCANF_ARRAY_ELEM_SET( Samples, n, NN ); } n+= 1; } if( sizeof(NECtimer)<=8 ){ resetTemps= 1; } } } } if( n< Time->N ){ Resize_ascanf_Array(sampleT, n, NULL ); Resize_ascanf_Array(Delta, n, NULL ); Resize_ascanf_Array(DDelta, n, NULL ); Resize_ascanf_Array(sumPos, n, NULL ); Resize_ascanf_Array(sumNeg, n, NULL ); Resize_ascanf_Array(sDTpos, n, NULL ); Resize_ascanf_Array(sDTneg, n, NULL ); Resize_ascanf_Array(Samples, n, NULL ); } *result= n; } return(!ascanf_arg_error); }
void dn_elliptic(decNumber *sn, decNumber *cn, decNumber *dn, const decNumber *u, const decNumber *m) { decNumber a, b, e, f, g; decNumber s_n, c_n, d_n; decNumber MU[ELLIPTIC_N], NU[ELLIPTIC_N], C[ELLIPTIC_N], D[ELLIPTIC_N]; decNumber sin_umu, cos_umu, t, r; int n = 0; #define mu(n) (MU + (n)) #define nu(n) (NU + (n)) #define c(n) (C + (n)) #define d(n) (D + (n)) if (sn == NULL) sn = &s_n; if (cn == NULL) cn = &c_n; if (dn == NULL) dn = &d_n; dn_abs(&a, m); if (dn_lt(&const_1, &a)) { cmplx_NaN(sn, cn); set_NaN(dn); return; } if (dn_lt(&a, &const_1e_32)) { dn_sincos(u, sn, cn); dn_1(dn); return; } dn_m1(&a, m); if (dn_abs_lt(&a, &const_1e_32)) { dn_sinhcosh(u, &a, &b); decNumberRecip(cn, &b); dn_multiply(sn, &a, cn); decNumberCopy(dn, cn); return; } dn_1(mu(0)); dn_1m(&a, m); dn_sqrt(nu(0), &a); for (;;) { dn_add(&g, mu(n), nu(n)); dn_abs(&a, &g); dn_mulpow10(&b, &a, 32); dn_mul2(&a, &b); dn_subtract(&e, mu(n), nu(n)); dn_abs(&f, &e); if (dn_gt(&a, &f)) break; dn_div2(mu(n+1), &g); dn_multiply(&a, mu(n), nu(n)); dn_sqrt(nu(n+1), &a); n++; if (n >= ELLIPTIC_N-1) break; } dn_multiply(&a, u, mu(n)); dn_sincos(&a, &sin_umu, &cos_umu); if (dn_abs_lt(&sin_umu, dn_abs(&b, &cos_umu))) dn_divide(&t, &sin_umu, &cos_umu); else dn_divide(&t, &cos_umu, &sin_umu); dn_multiply(c(n), mu(n), &t); dn_1(d(n)); while (n > 0) { n--; dn_multiply(c(n), d(n+1), c(n+1)); decNumberSquare(&a, c(n+1)); dn_divide(&r, &a, mu(n+1)); dn_add(&a, &r, nu(n)); dn_add(&b, &r, mu(n)); dn_divide(d(n), &a, &b); } cmplxAbs(&f, &b, &const_1, c(0)); if (decNumberIsNegative(&e)) { dn_1m(&a, m); dn_sqrt(&g, &a); dn_divide(dn, &g, d(0)); dn_divide(cn, dn, &f); if (decNumberIsNegative(&cos_umu)) dn_minus(cn, cn); dn_divide(&a, c(0), &g); dn_multiply(sn, cn, &a); } else { decNumberCopy(dn, d(0)); dn_divide(sn, &const_1, &f); if (decNumberIsNegative(&sin_umu)) dn_minus(sn, sn); dn_multiply(cn, c(0), sn); } #undef mu #undef nu #undef c #undef d }
int ascanf_strstr_count ( ASCB_ARGLIST ) { ASCB_FRAME_SHORT ascanf_Function *s1, *s2, *af; static ascanf_Function AF= {NULL}; static char *AFname= "StrStr-Static-StringPointer"; af= &AF; if( AF.name ){ double oa= af->own_address; xfree(af->usage); memset( af, 0, sizeof(ascanf_Function) ); af->own_address= oa; } else{ af->usage= NULL; af->type= _ascanf_variable; af->is_address= af->take_address= True; af->is_usage= af->take_usage= True; af->internal= True; af->name= AFname; take_ascanf_address(af); } af->name= AFname; af->type= _ascanf_variable; af->is_address= af->take_address= True; af->is_usage= af->take_usage= True; af->internal= True; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 2 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_strstr_count", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || !s1->usage) ){ if( s1 ){ fprintf( StdErr, " (warning: 1st argument [%s=%s,\"%s\"] is not a valid string)== ", s1->name, ad2str( s1->value, d3str_format, 0), (s1->usage)? s1->usage : "<NULL>" ); } else{ fprintf( StdErr, " (warning: 1st argument is NULL)== " ); } } if( !(s2= parse_ascanf_address(args[1], 0, "ascanf_strstr_count", (int) ascanf_verbose, NULL )) || (s2->type== _ascanf_procedure || s2->type== _ascanf_function || !s2->usage) ){ if( s2 ){ fprintf( StdErr, " (warning: 2nd argument [%s=%s,\"%s\"] is not a valid string)== ", s2->name, ad2str( s2->value, d3str_format, 0), (s2->usage)? s2->usage : "<NULL>" ); } else{ fprintf( StdErr, " (warning: 2nd argument is NULL)== " ); } } *result= 0; if( s1 && s2 && s1->usage && s2->usage ){ char *c= s1->usage; *result= 0; while( c && *c && (c= strstr( c, s2->usage )) ){ *result+= 1; c++; } } } return(!ascanf_arg_error); }
int ascanf_strrstr ( ASCB_ARGLIST ) { ASCB_FRAME_SHORT ascanf_Function *s1, *s2, *af; static ascanf_Function AF= {NULL}; static char *AFname= "StrRStr-Static-StringPointer"; af= &AF; if( AF.name ){ double oa= af->own_address; xfree(af->usage); memset( af, 0, sizeof(ascanf_Function) ); af->own_address= oa; } else{ af->usage= NULL; af->type= _ascanf_variable; af->is_address= af->take_address= True; af->is_usage= af->take_usage= True; af->internal= True; af->name= AFname; take_ascanf_address(af); } af->name= AFname; af->type= _ascanf_variable; af->is_address= af->take_address= True; af->is_usage= af->take_usage= True; af->internal= True; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 2 ){ ascanf_arg_error= 1; } else{ if( !(s1= parse_ascanf_address(args[0], 0, "ascanf_strrstr", (int) ascanf_verbose, NULL )) || (s1->type== _ascanf_procedure || s1->type== _ascanf_function || !s1->usage) ){ if( s1 ){ fprintf( StdErr, " (warning: 1st argument [%s=%s,\"%s\"] is not a valid string)== ", s1->name, ad2str( s1->value, d3str_format, 0), (s1->usage)? s1->usage : "<NULL>" ); } else{ fprintf( StdErr, " (warning: 1st argument is NULL)== " ); } } if( !(s2= parse_ascanf_address(args[1], 0, "ascanf_strrstr", (int) ascanf_verbose, NULL )) || (s2->type== _ascanf_procedure || s2->type== _ascanf_function || !s2->usage) ){ if( s2 ){ fprintf( StdErr, " (warning: 2nd argument [%s=%s,\"%s\"] is not a valid string)== ", s2->name, ad2str( s2->value, d3str_format, 0), (s2->usage)? s2->usage : "<NULL>" ); } else{ fprintf( StdErr, " (warning: 2nd argument is NULL)== " ); } } if( ascanf_SyntaxCheck ){ /* When compiling/ checking syntax, we *must* return a safe pointer of the correct type. \ Otherwise, printf[] might complain. NB: this means that the SyntaxCheck field must be \ set in this function's entry in the function table! */ *result= af->own_address; } else{ *result= 0; if( s1 && s2 && s1->usage && s2->usage ){ char *c= strrstr( s1->usage, s2->usage ); if( c ){ xfree( af->usage ); af->usage= strdup( c ); *result= af->own_address; } } } } return(!ascanf_arg_error); }
int ascanf_timecode ( ASCB_ARGLIST ) { ASCB_FRAME_SHORT double t; int base= 0, hbase= 3600, mbase= 60; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ int hh, mm, ssi, ssir; double ss; char buf[256]; ascanf_Function *af= NULL; if( ascanf_arguments> 1 && ASCANF_TRUE(args[1]) && args[1]> 0 ){ base= (int) args[1]; hbase*= base; mbase*= base; t= args[0] * base; hh= (int) (t / hbase); mm= (int) ((t-hh*hbase) / mbase); ss= (t-hh*hbase-mm*mbase); ssi= (int) (ss/base); ssir= (int) ((ss-ssi*base)); snprintf( buf, sizeof(buf)/sizeof(char), "%02d:%02d:%02d.%0d/%d", hh, mm, ssi, ssir, base ); } else{ base= 100; hbase*= base; mbase*= base; t= args[0] * base; hh= (int) (t / hbase); mm= (int) ((t-hh*hbase) / mbase); ss= (t-hh*hbase-mm*mbase)/ base; snprintf( buf, sizeof(buf)/sizeof(char), "%02d:%02d:%s", hh, mm, ad2str(ss, d3str_format, NULL) ); } if( ascanf_arguments> 2 && ASCANF_TRUE(args[2]) ){ int take_usage; if( (af= parse_ascanf_address(args[2], _ascanf_variable, "ascanf_timecode", (int) ascanf_verbose, &take_usage )) && !take_usage ){ af= NULL; if( ascanf_verbose ){ fprintf( StdErr, " (2nd argument %s is not a valid stringpointer, ignored) ", ad2str( args[2], d3str_format, NULL ) ); } } } if( !af ){ static ascanf_Function AF= {NULL}; static char *AFname= "timecode-Static-StringPointer"; af= &AF; if( AF.name ){ double oa= af->own_address; xfree(af->usage); memset( af, 0, sizeof(ascanf_Function) ); af->own_address= oa; } else{ af->usage= NULL; af->type= _ascanf_variable; af->is_address= af->take_address= True; af->is_usage= af->take_usage= True; af->internal= True; af->name= AFname; take_ascanf_address(af); } af->name= AFname; af->type= _ascanf_variable; af->is_address= af->take_address= True; af->is_usage= af->take_usage= True; af->internal= True; } xfree( af->usage ); af->usage= strdup( buf ); *result= af->own_address; } return( !ascanf_arg_error ); }