📄 scicalc.cxx
字号:
but_ln->resize(FL_BUTT_GEO(2, 2)); but_int->resize(FL_BUTT_GEO(3, 2)); but_dr->resize(FL_BUTT_GEO(4, 2)); but_drg->resize(FL_BUTT_GEO(5, 2)); but_leftbr->resize(FL_BUTT_GEO(1, 3)); but_rightbr->resize(FL_BUTT_GEO(2, 3)); but_exch->resize(FL_BUTT_GEO(3, 3)); but_invx->resize(FL_BUTT_GEO(4, 3)); but_fact->resize(FL_BUTT_GEO(5, 3)); if (SciMode) { tmp_y += tmp_h; sci_view_window->show(); } else if (!SciMode) { tmp_y = 70; } tmp_h = h - tmp_y; SetButtonWindowGeometry(tmp_x, tmp_y, tmp_w, tmp_h, 5, 5); simple_view_window->resize(tmp_x, tmp_y, tmp_w, tmp_h); but_7->resize(FL_BUTT_GEO(1, 2)); but_8->resize(FL_BUTT_GEO(2, 2)); but_9->resize(FL_BUTT_GEO(3, 2)); but_4->resize(FL_BUTT_GEO(1, 3)); but_5->resize(FL_BUTT_GEO(2, 3)); but_6->resize(FL_BUTT_GEO(3, 3)); but_1->resize(FL_BUTT_GEO(1, 4)); but_2->resize(FL_BUTT_GEO(2, 4)); but_3->resize(FL_BUTT_GEO(3, 4)); but_0->resize(FL_BUTT_GEO(1, 5)); but_dot->resize(FL_BUTT_GEO(2, 5)); but_sign->resize(FL_BUTT_GEO(3, 5)); but_C->resize(FL_BUTT_GEO(4, 2)); but_AC->resize(FL_BUTT_GEO(5, 2)); but_X->resize(FL_BUTT_GEO(4, 3)); but_div->resize(FL_BUTT_GEO(5, 3)); but_plus->resize(FL_BUTT_GEO(4, 4)); but_minus->resize(FL_BUTT_GEO(5, 4)); but_pi->resize(FL_BUTT_GEO(4, 5)); but_eval->resize(FL_BUTT_GEO(5, 5)); but_Mplus->resize(FL_BUTT_GEO(1, 1)); but_Mmult->resize(FL_BUTT_GEO(2, 1)); but_Mclear->resize(FL_BUTT_GEO(3, 1)); but_Mst->resize(FL_BUTT_GEO(4, 1)); but_Mrc->resize(FL_BUTT_GEO(5, 1));// status_window->redraw();// simple_view_window->redraw();// sci_view_window->redraw();}voidSciCalc::run(int px, int py){#ifdef NANOX/* Window xid; GR_WINDOW_INFO win_info; GR_WM_PROPERTIES win_props; Window parent_xid; win_props.flags = GR_WM_FLAS_PROPS; win_props.props = DEF_STYLE; GrSetWMProperties(xid, &win_props);*/// main_window->wm_props = DEF_STYLE;#endif main_window->show(); Fl::run();}voidSciCalc::handle_number(double numb){ 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); }}voidSciCalc::handle_operator(Operator op){ 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; }}voidSciCalc::change_base(int newbase){ int oldbase; oldbase = base; base = newbase; but_2->labelcolor(0); but_3->labelcolor(0); but_4->labelcolor(0); but_5->labelcolor(0); but_6->labelcolor(0); but_7->labelcolor(0); but_8->labelcolor(0); but_9->labelcolor(0); if (base <= 8) { but_9->labelcolor(FL_WHITE); } if (base == 2) { but_8->labelcolor(FL_WHITE); but_7->labelcolor(FL_WHITE); but_6->labelcolor(FL_WHITE); but_5->labelcolor(FL_WHITE); but_4->labelcolor(FL_WHITE); but_3->labelcolor(FL_WHITE); but_2->labelcolor(FL_WHITE); } simple_view_window->redraw(); set_display(value[top], NORM); ready = 1; if ((oldbase == 16) || (base == 16)) setnormlabels();}voidSciCalc::set_display(double val, mode behind){ 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();}voidSciCalc::set_memdisp(){ if (mem) box_M->value("M"); else box_M->value(""); box_M->redraw();}voidSciCalc::set_drgdisp(){ if (drgmode == 0) box_DEGRAD->value("DEG"); else if (drgmode == 1) box_DEGRAD->value("RAD"); else box_DEGRAD->value("GRAD"); box_DEGRAD->redraw();}voidSciCalc::set_brktdisp(){ char dispstr[40]; if (currentbrkt > 0) { sprintf(dispstr, "%d [ max %d", currentbrkt, MaxNumBrkts); box_bracket->value(dispstr); } else box_bracket->value(""); box_bracket->redraw();}voidSciCalc::add_left_bracket(){ if (currentbrkt < MaxNumBrkts) { currentbrkt++; startbrkt[currentbrkt] = top; ready = 1; set_brktdisp(); }}voidSciCalc::add_right_bracket(){ 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();}voidSciCalc::factorial(){ 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; }}voidSciCalc::exchange(){ 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; }}voidSciCalc::exponent_pi(){ 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); }}voidSciCalc::calc(int i){ 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; }}voidSciCalc::init_value(int lev){ 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(); }}voidSciCalc::cvttobase(double num, int base, mode behind, char *str){ 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--; }}voidSciCalc::setnormlabels(){ 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();}voidSciCalc::setinvlabels(){ 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();}voidSciCalc::mem_exchange(){ double temp; temp = mem; mem = value[top]; value[top] = temp; set_display(value[top], NORM); ready = 1; set_memdisp();}doubleSciCalc::to_drg(double angle){ if (drgmode == 0) return (M_PI * angle / 180.0); else if (drgmode == 2) return (M_PI * angle / 100.0); else return (angle);}doubleSciCalc::from_drg(double angle){ if (drgmode == 0) return (180.0 * angle / M_PI); else if (drgmode == 2) return (100.0 * angle / M_PI); else return (angle);}voidSciCalc::memexch(){ 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 + -