⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scicalc.fld

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 FLD
📖 第 1 页 / 共 2 页
字号:
  }  Function {handle_number(double numb)} {private  } {    code {int first;double sign;	if (ready) init_value(top);	if (numb == -1.0) 	if (dot) /* check whether we already have a dot */		return;	else 	{		dot = 1;		set_display(value[top],DOT);		return;	}	if (emode) 	{		sign = copysign(1.0, (double)exponent);		if (abs(exponent)*10 + numb > 999) 		{ /* cycle if exponent has > 3 digits */			first = (int)floor((double)abs(exponent)/100.0);			exponent = abs(exponent) - 100*first;			exponent *= (int)sign;		}		exponent = exponent*10 + (int) (sign*numb);		value[top] = mantissa*pow(10.0, (double)exponent);		set_display(mantissa, EXP);	}	else if (numb < base)	{ /* both decimal and non decimal number entry */		sign = copysign(1.0, value[top]);		if (dot && behind < 9) 		{			behind++;			diver = diver/(double)base;			value[top] += sign*diver*numb;		}		else 		if ((! dot) && (value[top] < 1.0e10))			value[top] = (double)base*value[top] + sign*numb;		set_display(value[top],(mode)behind);	}} {}  }  Function {handle_operator(Operator op)} {private  } {    code {int prevop, i, finished;	switch (op)	{		case PLUS:		case MINUS:		case MULT:		case DIV:		case POW:		case INVPOW:			finished = 0;			do 			{				if (top == startbrkt[currentbrkt]) finished = 1; /* is 1st operator */				if (! finished) 				{ /* compare priority of previous operators with current op */					prevop = oper[top-1];					if (priority[prevop] < priority[op])						finished = 1;					else 					{ /* last op can be calculated */						top--;    					calc(top);					}				}			} while (! finished);			oper[top] = op;			init_value(top+1);			set_display(value[top-1],NORM);			break;		case EVAL:			while (currentbrkt > 0) add_right_bracket();			for (i = top; i > 0; i--) calc(i-1);			top = 0;			ready = 1;			set_display(value[top],NORM);			break;	}} {}  }  Function {change_base(int newbase)} {private  } {    code {int oldbase;	oldbase = base;	base = newbase;	set_display(value[top], NORM);	ready = 1;	if ((oldbase == 16) || (base == 16)) setnormlabels();} {}  }  Function {set_display(double val,mode behind)} {open private  } {    code {int i;char dispstr[40], expstr[10], str2[10];	/* number or operator handled to get here so reset inv stuff *//*	if (inv) 	{		inv = 0;		check_inv->value(0);		setnormlabels();	}*/	if (behind >= 0) 	{ /* format with appropriate number of decimal places */		if (base == 10) 		{			emode = 0;			strcpy(str2,"%.1f");			str2[2] = behind + '0';			sprintf(dispstr,str2,val);		}		else /* non base 10 display */			cvttobase(val, base, behind, dispstr);	}	else 	if (behind == DOT) 	{ /* display the . at the right */		if (base == 10) 		{			emode = 0;			sprintf(dispstr,"%.1f",val);			dispstr[strlen(dispstr)-1] = 0;		}		else			cvttobase(val, base, behind, dispstr);	}	else if (behind == NORM) 	{ /* normal display */		if (base == 10) 		{			emode = 0;			sprintf(dispstr,"%.9g",val);		}		else /* non base 10 display */			cvttobase(val, base, behind, dispstr);	}	else 	{ /* exponent entering display */		sprintf(dispstr,"%.8f",val);		for (i = strlen(dispstr); dispstr[i-1] == '0'; i--);		dispstr[i] =0;		strcat(dispstr, "e");		sprintf(expstr,"%d",exponent);		strcat(dispstr, expstr);	}	strcat(dispstr," ");	dispstr[17] = 0;	leddisplay->value(dispstr);	leddisplay->redraw();} {}  }  Function {set_memdisp()} {open private  } {    code {if (mem)		box_M->value("M");	else		box_M->value("");	box_M->redraw();} {}  }  Function {set_drgdisp()} {open private  } {    code {if (drgmode == 0)		 box_DEGRAD->value("DEG");	else	 if (drgmode == 1)		box_DEGRAD->value( "RAD");	else		box_DEGRAD->value( "GRAD");	box_DEGRAD->redraw();} {}  }  Function {set_brktdisp()} {open private  } {    code {char dispstr[40];	if (currentbrkt > 0)	{		sprintf(dispstr, "%d [ max %d", currentbrkt, MaxNumBrkts);		box_bracket->value(dispstr);	}	else		box_bracket->value("");	box_bracket->redraw();} {}  }  Function {add_left_bracket()} {open private  } {    code {if (currentbrkt < MaxNumBrkts) 	{		currentbrkt++;		startbrkt[currentbrkt] = top;		ready = 1;		set_brktdisp();	}} {}  }  Function {add_right_bracket()} {private  } {    code {int i;	if (currentbrkt > 0) 	{		for (i = top; i > startbrkt[currentbrkt]; i--) calc(i-1);		top = startbrkt[currentbrkt];		currentbrkt--;		ready = 1;	}	set_display(value[top],NORM);	set_brktdisp();} {}  }  Function {factorial()} {open  } {    code {double lg, alpha;  /* uses gamma functions to get result for non-integer values */	alpha = value[top] + 1.0;	if ((floor(alpha) == alpha)&&(alpha <= 0.0))	{		init_value(0);		leddisplay->value("Error: -ve integer ");		leddisplay->redraw();	}	else	if (alpha > 32)	 {		lg = exp(gammaln(alpha));    		value[top] = lg;   		 set_display(value[top],NORM);		ready = 1;	}	else	if (alpha > 1.0)	{		int n = (int)truncf(alpha);		lg = 1.0;		for (int i = 1; i <n; i++) lg *= i;		value[top] = lg;		set_display(value[top],NORM);		ready = 1;	}} {}  }  Function {exchange()} {} {    code {double temp;  /* check if we have 2 values to exchange */  if (top > startbrkt[currentbrkt]) {    temp = value[top];    value[top] = value[top-1];    value[top-1] = temp;    set_display(value[top],NORM);    ready = 1;  }} {}  }  Function {exponent_pi()} {} {    code {if ((value[top] == 0.0) || (ready)) {    value[top] = M_PI;    set_display(value[top],NORM);    ready = 1;  }  else if ((! emode) && (base == 10)) {    emode = 1;    exponent = 0;    mantissa = value[top];    set_display(mantissa,EXP);  }} {}  }  Function {calc(int i)} {} {    code {switch (oper[i])	 {		case PLUS:	value[i] += value[i+1]; break;		case MINUS:	value[i] -= value[i+1]; break;		case MULT:	value[i] *= value[i+1]; break;		case DIV:	value[i] /= value[i+1]; break;		case POW:	value[i] = pow(value[i], value[i+1]); break;		case INVPOW: value[i] = pow(value[i], 1.0/value[i+1]); break;	}} {}  }  Function {init_value(int lev)} {private  } {    code {top = lev;	value[top] = 0.0;	ready = 0;	emode = 0;	dot = 0;	diver = 1.0;	behind = 0;	if (inv) 	{		inv = 0;		check_inv->value(0);		setnormlabels();	}} {}  }  Function {cvttobase(double num,int base,mode behind,char *str)} {private  } {    code {double sign, div;int place, digit, i;char digstr[2];	sign = copysign(1.0, num);	num *= sign;	if (sign == -1.0)		sprintf(str, "-");	else		str[0] = 0;	if (num == 0.0) 	{		sprintf(str, "0");		if (behind > 0) 		{			strcat(str, ".");			for(i = 0; i < behind; i++) strcat(str, "0");		}		return;	}	place = (int)( log(num)/log((double)base) );	if (place < 0) place = 0;	do 	{		div = pow((double)base, (double)place);		digit = (int)(num/div);		num -= (double)digit*div;		if (place == -1) strcat(str, ".");		place--;		sprintf(digstr, "%x", digit);		strcat(str, digstr);		if (strlen(str) > 18) 		{			sprintf(str, "can't display");			return;		}	} while ((place >= 0) || ((place >= -9) && (num != 0.0)));	if ((place == -1) && ((behind == DOT) || (behind > 0)))		strcat(str, ".");	while ((behind > 0) && (behind >= -place)) 	{		strcat(str, "0");		place--;	}} {}  }  Function {setnormlabels()} {private  } {    code {if (base <= 10)	{		but_sqrt->label("sqrt");		but_pow->label("x^y");		but_sin->label("sin");		but_cos->label("cos");		but_tan->label("tan");		but_log->label("log");		but_sqrt->labelcolor(FL_BLUE);		but_pow->labelcolor(FL_BLUE);		but_sin->labelcolor(FL_BLUE);		but_cos->labelcolor(FL_BLUE);		but_tan->labelcolor(FL_BLUE);		but_log->labelcolor(FL_BLUE);	}	else	{		but_sqrt->label("a");		but_pow->label("b");		but_sin->label("c");		but_cos->label("d");		but_tan->label("e");		but_log->label("f");		but_sqrt->labelcolor(FL_BLACK);		but_pow->labelcolor(FL_BLACK);		but_sin->labelcolor(FL_BLACK);		but_cos->labelcolor(FL_BLACK);		but_tan->labelcolor(FL_BLACK);		but_log->labelcolor(FL_BLACK);	}	but_ln->label("ln");	but_int->label("int");	but_dr->label("d->r");	but_Mplus->label("M+");	but_Mmult->label("M*");	but_Mclear->label("MC");	but_sqrt->redraw();	but_pow->redraw();	but_sin->redraw();	but_cos->redraw();	but_tan->redraw();	but_log->redraw();	but_ln->redraw();	but_int->redraw();	but_dr->redraw();	but_Mplus->redraw();	but_Mmult->redraw();	but_Mclear->redraw();} {}  }  Function {setinvlabels()} {private  } {    code {if (base <= 10)	{		but_sqrt->label("x^2");		but_pow->label("x^1/y");		but_sin->label("asin");		but_cos->label("acos");		but_tan->label("atan");		but_log->label("10^x");		but_sqrt->labelcolor(FL_BLUE);		but_pow->labelcolor(FL_BLUE);		but_sin->labelcolor(FL_BLUE);		but_cos->labelcolor(FL_BLUE);		but_tan->labelcolor(FL_BLUE);		but_log->labelcolor(FL_BLUE);	}	else	{		but_sqrt->label("a");		but_pow->label("b");		but_sin->label("c");		but_cos->label("d");		but_tan->label("e");		but_log->label("f");		but_sqrt->labelcolor(FL_BLACK);		but_pow->labelcolor(FL_BLACK);		but_sin->labelcolor(FL_BLACK);		but_cos->labelcolor(FL_BLACK);		but_tan->labelcolor(FL_BLACK);		but_log->labelcolor(FL_BLACK);	}	but_ln->label("e^x");	but_int->label("frac");	but_dr->label("r->d");	but_Mplus->label("M-");	but_Mmult->label("M/");	but_Mclear->label("Mex");	but_sqrt->redraw();	but_pow->redraw();	but_sin->redraw();	but_cos->redraw();	but_tan->redraw();	but_log->redraw();	but_ln->redraw();	but_int->redraw();	but_dr->redraw();	but_Mplus->redraw();	but_Mmult->redraw();	but_Mclear->redraw();} {}  }  Function {mem_exchange()} {private  } {    code {double temp;	temp = mem;	mem = value[top];	value[top] = temp;	set_display(value[top],NORM);	ready = 1;	set_memdisp();} {}    code {printf("Hello, World!\\n");} {}  }  Function {to_drg(double angle)} {private return_type double  } {    code {if (drgmode == 0)		return (M_PI*angle/180.0);	else 	if (drgmode == 2)		return (M_PI*angle/100.0);	else		return (angle);} {}  }  Function {from_drg(double angle)} {private return_type double  } {    code {if (drgmode == 0)		return (180.0*angle/M_PI);	else 	if (drgmode == 2)		return (100.0*angle/M_PI);	else		return (angle);} {}  }  Function {memexch()} {open  } {    code {double temp;	temp = mem;	mem = value[top];	value[top] = temp;	set_display(value[top],NORM);	ready = 1;	set_memdisp();} {}  }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -