void func_import_basic(int n) { func_init(); // default op for debug only func_scope_set(n,func_op_builtin_new()); func_scope_set(n,func_op_def_new()); func_scope_set(n,func_op_list_new()); func_scope_set(n,func_op_table_new()); func_scope_set(n,func_op_strings_new()); func_scope_set(n,func_op_scope_new()); // basic func_scope_set(n,func_op_nan_new()); func_scope_set(n,func_op_inf_new()); func_scope_set(n,func_op_zero_new()); func_scope_set(n,func_op_one_new()); func_scope_set(n,func_op_bigint_new()); func_scope_set(n,func_op_real_new()); func_scope_set(n,func_op_complex_new()); func_scope_set(n,func_op_var_new()); func_scope_set(n,func_op_add_new()); func_scope_set(n,func_op_mul_new()); func_scope_set(n,func_op_sqrt_new()); func_scope_set(n,func_op_exp_new()); func_scope_set(n,func_op_log_new()); func_scope_set(n,func_op_pow_new()); func_scope_set(n,func_op_sin_new()); func_scope_set(n,func_op_cos_new()); func_scope_set(n,func_op_tan_new()); func_scope_set(n,func_op_asin_new()); func_scope_set(n,func_op_acos_new()); func_scope_set(n,func_op_atan_new()); func_scope_set(n,func_op_sinh_new()); func_scope_set(n,func_op_cosh_new()); func_scope_set(n,func_op_tanh_new()); func_scope_set(n,func_op_asinh_new()); func_scope_set(n,func_op_acosh_new()); func_scope_set(n,func_op_atanh_new()); func_scope_set(n,func_op_ivec_new()); func_scope_set(n,func_op_rvec_new()); func_scope_set(n,func_op_cvec_new()); func_scope_set(n,func_op_rmat_new()); func_scope_set(n,func_op_cmat_new()); func_scope_set(n,func_op_begin_new()); func_scope_set(n,func_op_end_new()); func_scope_set(n,func_op_set_new()); func_scope_set(n,func_op_print_new()); func_scope_set(n,func_op_eval_new()); func_scope_set(n,func_op_evalf_new()); func_scope_set(n,func_op_expand_new()); func_scope_set(n,func_op_diff_new()); func_scope_set(n,func_op_grad_new()); func_scope_set(n,func_op_gbasis_new()); func_scope_set(n,func_def("I", func_complex_i(),0,0)); func_scope_set(n,func_def("i", func_sqrt(func_bigint_int(-1,1)),0,0)); func_scope_set(n,func_def("PI",func_mul(func_atan(func_one()),func_bigint_int(4,1)),0,0)); func_scope_set(n,func_def("Pi",func_mul(func_atan(func_one()),func_bigint_int(4,1)),0,0)); func_scope_set(n,func_def("pi",func_mul(func_atan(func_one()),func_bigint_int(4,1)),0,0)); }
static void func_two(void) { union wedgie_union u; struct wedgie_data d = { 42, "forty-two" }; char multidim[4][8][16] = {0}; short otherdim[3][6]; int (*func)(int) = myfunc; printf("initialize some data\n"); fflush(stdout); u.one = 1; u.s.inner2 = 2; d.bit1 = 1; d.bit2 = 0; d.moo = 13; d.bigbits = 0x29999; d.aftermoo = 4.5; d.lone.a = 3; d.lone.b = 4; d.ltwo.a = 5; d.ltwo.b = 6; d.arr[0] = 9; d.arr[1] = 8; d.arr[2] = 7; d.arr[3] = 6; func(3); printf("call func_one\n"); fflush(stdout); func_one(&d, 32, "hello", wee_two, d #ifndef __sparc__ , u #endif ); printf("func_one called\n"); }
func_t *func_poly_clone_coeff_ntarm(func_t *f,int n) { func_t *a; if(!func_is_poly(f)){ return NULL; } a=func_poly_get_mono_ntarm(f,n); if(a==NULL){ return func_zero(); } if(func_is_number(a)){ return func_clone(FR(a)); } a=func_mono_get_coeff(a); if(a==NULL){ return func_one(); } return func_clone(FR(a)); }
func_t *func_diff_atanh_pow1(func_t *f, int var) { func_t *fx=NULL,*g=NULL,*gx=NULL,*h=NULL; if(!func_is(f,"atanh") || func_power(f)!=1){ FUNC_ERROR_ARG1("func_diff_atanh",f); } g=f->a[0]; gx=func_diff(FR(g),func_var1(var,1)); h=func_pow_n(FR(g),2); h=func_sub(func_one(),h); fx=func_div(gx,h); f=func_del(f); return fx; }
func_t *func_expand_mul_pow_n(func_t *f) { int i; func_t *g=NULL; if(func_is_mul(f) && func_power(f)!=1){ g=func_one(); for(i=0; i<func_asize(f); i++){ g=func_mul(g,func_expand(func_pow_n(FR(f->a[i]),func_power(f)))); } }else{ FUNC_ERROR_ARG1("func_expand_mul_pow_n",f); } f=func_del(f); return g; }
func_t *func_poly_lm_lcm(func_t *f, func_t *g) { func_t *lcm=NULL,*f_lm=NULL,*g_lm=NULL; if(func_is_poly(f) && func_is_poly(g)){ f_lm=func_poly_get_lm(f); g_lm=func_poly_get_lm(g); if (f_lm!=NULL && g_lm!=NULL) { lcm=func_var_lcm(FR(f_lm),FR(g_lm)); } else if(f_lm==NULL && g_lm!=NULL) { lcm=FR(g_lm); } else if(f_lm!=NULL && g_lm==NULL) { lcm=FR(f_lm); } else { lcm=func_one(); } } f_lm=NULL; g_lm=NULL; f=func_del(f); g=func_del(g); return lcm; }
func_t *func_expand_mul_pow1(func_t *f) { int i; func_t *g=NULL,*h=NULL; if(func_is_mul(f) && func_power(f)==1){ g=func_one(); for(i=0; i<func_asize(f); i++){ h=func_expand(FR(f->a[i])); if((func_is_add(g) && func_power(g)==1) || (func_is_add(h) && func_power(h)==1)){ g=func_expand(func_mul(g,h)); }else{ g=func_mul(g,h); } } }else{ FUNC_ERROR_ARG1("func_expand_mul_pow1",f); } f=func_del(f); return g; }
int32_t main(int32_t argc, char *argv[]) { const char *options = "vhteobdf:"; int32_t opt; int32_t tracer; int32_t do_stderr = QB_FALSE; int32_t do_stdout = QB_FALSE; int32_t do_dump_blackbox = QB_FALSE; char *logfile = NULL; int32_t log_fd = -1; while ((opt = getopt(argc, argv, options)) != -1) { switch (opt) { case 'd': do_dump_blackbox = QB_TRUE; break; case 't': do_threaded = QB_TRUE; break; case 'e': do_stderr = QB_TRUE; break; case 'o': do_stdout = QB_TRUE; break; case 'b': do_blackbox = QB_TRUE; break; case 'f': logfile = optarg; break; case 'v': _log_priority++; break; case 'h': default: show_usage(argv[0]); exit(0); break; } } if (do_dump_blackbox) { qb_log_blackbox_print_from_file("simple-log.fdata"); exit(0); } signal(SIGSEGV, sigsegv_handler); qb_log_init("simple-log", LOG_USER, LOG_INFO); qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_THREADED, do_threaded); qb_log_tags_stringify_fn_set(my_tags_stringify); if (do_stderr) { qb_log_filter_fn_set(m_filter); qb_log_format_set(QB_LOG_STDERR, "[%p] %4g: %f:%l %b"); qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); tracer = qb_log_custom_open(trace_logger, NULL, NULL, NULL); qb_log_ctl(tracer, QB_LOG_CONF_ENABLED, QB_TRUE); qb_log_format_set(tracer, "%4g: %n() %b"); qb_log_filter_ctl2(tracer, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, __FILE__, LOG_TRACE, 200); } if (do_stdout) { qb_log_filter_ctl2(QB_LOG_STDOUT, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, __FILE__, LOG_ALERT, QB_MIN(LOG_DEBUG, _log_priority)); qb_log_format_set(QB_LOG_STDOUT, "[%p] %4g: %f:%l %b"); qb_log_ctl(QB_LOG_STDOUT, QB_LOG_CONF_ENABLED, QB_TRUE); } if (do_blackbox) { qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, "*", LOG_DEBUG); qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, 4096); qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE); qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE); } if (logfile) { log_fd = qb_log_file_open(logfile); qb_log_filter_ctl(log_fd, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, __FILE__, _log_priority); qb_log_format_set(log_fd, "[%N] %t %n() [%p] %b"); qb_log_ctl(log_fd, QB_LOG_CONF_THREADED, do_threaded); qb_log_ctl(log_fd, QB_LOG_CONF_ENABLED, QB_TRUE); } if (do_threaded) { qb_log_thread_start(); } qb_log(LOG_DEBUG, "hello"); qb_log(LOG_INFO, "this is an info"); qb_log(LOG_NOTICE, "hello - notice?"); func_one(); func_two(); qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); qb_log(LOG_WARNING, "no syslog"); qb_log(LOG_ERR, "no syslog"); #if 0 // test blackbox logfile = NULL; logfile[5] = 'a'; #endif if (do_blackbox) { qb_log_blackbox_write_to_file("simple-log.fdata"); qb_log_blackbox_print_from_file("simple-log.fdata"); qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE); } qb_log_fini(); return 0; }