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

📄 math.cpp

📁 一个在linux下的shell的计算器
💻 CPP
字号:
/* * * * */#include <iostream>#include "math.h"#include "interpreter.h"using namespace std;//////long factorial(long x){ return ((x == 0) ? 1 : x*factorial(x-1));}double sign(double x) { return ((x == 0) ? 0 : ((x > 0) ? 1 : -1));}//////void LoadMath(ItemList & list){ list.Add(new Operation(PI, "pi", 0)); list.Add(new Operation(E, "e", 0)); list.Add(new Operation(PHI, "phi", 0)); list.Add(new Operation(RAND, "rand", 0)); list.Add(new Operation(ABS, "abs", 1)); list.Add(new Operation(SGN, "sign", 1)); list.Add(new Operation(CEIL, "ceil", 1)); list.Add(new Operation(FLOOR, "floor", 1)); list.Add(new Operation(ROUND, "round", 1)); list.Add(new Operation(INV, "inv", 1)); list.Add(new Operation(SQR, "sqr", 1)); list.Add(new Operation(SQRT, "sqrt", 1)); list.Add(new Operation(CBRT, "cbrt", 1)); list.Add(new Operation(EXP, "exp", 1)); list.Add(new Operation(EXP10, "exp10", 1)); list.Add(new Operation(EXP2, "exp2", 1)); list.Add(new Operation(FACT, "!", 1)); list.Add(new Operation(LN, "ln", 1)); list.Add(new Operation(LOG, "log", 1)); list.Add(new Operation(LOG2, "log2", 1)); list.Add(new Operation(SIN, "sin", 1)); list.Add(new Operation(COS, "cos", 1)); list.Add(new Operation(TAN, "tan", 1)); list.Add(new Operation(ASIN, "asin", 1)); list.Add(new Operation(ACOS, "acos", 1)); list.Add(new Operation(ATAN, "atan", 1)); list.Add(new Operation(SINH, "sinh", 1)); list.Add(new Operation(COSH, "cosh", 1)); list.Add(new Operation(TANH, "tanh", 1)); list.Add(new Operation(ASINH, "asinh", 1)); list.Add(new Operation(ACOSH, "acosh", 1)); list.Add(new Operation(ATANH, "atanh", 1)); list.Add(new Operation(PLUS, "+", 2)); list.Add(new Operation(MINUS, "-", 2)); list.Add(new Operation(MULT, "*", 2)); list.Add(new Operation(DIV, "/", 2)); list.Add(new Operation(POW, "pow", 2)); list.Add(new Operation(ROOT, "root", 2)); // Alias  list.Add(new Operation(PLUS, "plus", 2)); list.Add(new Operation(MINUS, "minus", 2)); list.Add(new Operation(MULT, "times", 2)); list.Add(new Operation(DIV, "divided", 2)); list.Add(new Operation(POW, "power", 2)); list.Add(new Operation(POW, "^", 2)); list.Add(new Operation(POW, "**", 2)); list.Add(new Operation(ROOT, "//", 2)); list.Add(new Operation(SQRT, "v-", 1)); list.Add(new Operation(EXP10, "10x", 1)); list.Add(new Operation(EXP2, "2x", 1)); list.Add(new Operation(LN, "logn", 1)); list.Add(new Operation(LOG, "log10", 1)); list.Add(new Operation(SGN, "sgn", 1)); list.Add(new Operation(INV, "\\", 1));}//////void BasicMathHelp(){ cout << endl << "Basic Mathematical operations: " << endl << endl; cout << "  +        Addition." << endl; cout << "  -        Substraction." << endl; cout << "  *        Multiplication." << endl; cout << "  /        Division." << endl; cout << "  pow      Power." << endl; cout << "  root     Root." << endl; cout << "  inv      Multiplicative inverse." << endl; cout << "  sqr      Square." << endl; cout << "  sqrt     Square root." << endl; cout << "  cbrt     Cube root." << endl; cout << "  exp      Exponential (base e)." << endl; cout << "  10x      Exponential (base 10)." << endl; cout << "  2x       Exponential (base 2)." << endl; cout << "  ln       Natural (base e) logarithm." << endl; cout << "  log      Base 10 logarithm." << endl; cout << "  log2     Base 2 logarithm." << endl; cout << "  abs      Absolute value." << endl;  cout << "  sgn      Sign." << endl; cout << "  round    Round to nearest integer." << endl; cout << "  ceil     Round up to nearest integer." << endl; cout << "  floor    Round down to nearest integer." << endl;}//////void TrigHelp(){ cout << endl << "Trigonometric functions: " << endl << endl; cout << "  sin      Sine." << endl; cout << "  cos      Cosine." << endl; cout << "  tan      Tangent." << endl; cout << "  asin     Arc sine." << endl; cout << "  acos     Arc cosine." << endl; cout << "  atan     Arc tangent." << endl; cout << "  sinh     Hyperbolic sine." << endl; cout << "  cosh     Hyperbolic cosine." << endl; cout << "  tanh     Hyperbolic tangent." << endl; cout << "  asinh    Arc hyperbolic sine." << endl; cout << "  acosh    Arc hyperbolic cosine." << endl; cout << "  atanh    Arc hyperbolic tangent." << endl;}//////void ConstantsHelp(){ cout << endl << "Mathematical constants: " << endl << endl; cout << "  pi       Circunference / diameter ratio." << endl; cout << "  e        Base of the natural logarithm." << endl; cout << "  phi      The \"Golden ratio\"." << endl;}

⌨️ 快捷键说明

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